У меня проблемы с использованием массива / матрицы, созданной в первом операторе if (if (choice == 1)) на более позднем этапе кода. Я хотел бы отредактировать массив (когда я упоминаю if (choice == 2), но массив, созданный в первом блоке кода "if", локализован. Как я могу обойти это?
#include "pch.h"
#include <iostream>
#include <vector>
int main()
{
if (choice == 1)
{
std::cout << "Choose a letter from A to C, where A = 1" << std::endl;
short matNamechoice;
std::cin >> matNamechoice;
if (matNamechoice == 1)
{
bool matAlive = true;
std::vector<int> matrixA(0);
std::cout << "How many elements would you like to add to Matrix" << matNamechoice << "?" << std::endl;
short matAelements;
std::cin >> matAelements;
std::cout << "For the " << matAelements << "elements that you have created, please choose \
each element value: " << std::endl;
for (int n = 0; n < matAelements; ++n)
{
std::cout << "ELEMENT NO " << n << ":" << std::endl;
int elementValue = 0;
std::cin >> elementValue;
matrixA.push_back(elementValue);
}
std::cout << matAelements << " elements have been appended to matrixA." << std::endl;
}
if (matNamechoice == 2)
{
bool matBLive = true;
std::vector<int> matrixB(0);
std::cout << "How many elements would you like to add to Matrix " << matNamechoice << "?" << std::endl;
short matBelements;
std::cin >> matBelements;
std::cout << "For the " << matBelements << "elements that you have created, please choose \
each element value: " << std::endl;
for (int n = 0; n < matBelements; ++n)
{
std::cout << "ELEMENT NO " << n << ":" << std::endl;
int elementValue = 0;
std::cin >> elementValue;
matrixB.push_back(elementValue);
}
std::cout << matBelements << " elements have been appended to matrixB." << std::endl;
}
if (matNamechoice == 3)
{
bool matCLive = true;
std::vector<int> matrixC(0);
std::cout << "How many elements would you like to add to Matrix" << matNamechoice << "?" << std::endl;
short matCelements;
std::cin >> matCelements;
std::cout << "For the " << matCelements << "elements that you have created, please choose \
each element value: " << std::endl;
for (int n = 0; n < matCelements; ++n)
{
std::cout << "ELEMENT NO " << n << ":" << std::endl;
int elementValue = 0;
std::cin >> elementValue;
matrixC.push_back(elementValue);
}
std::cout << matCelements << " elements have been appended to matrixC. \n \n" << std::endl;
}
}
if (choice == 2 && (matAlive == true))
std::cout << "LOADING MATRICIES..." << std::endl;
for (int n = 10; n <= 100; n += 10)
{
std::cout << n << "%" << std::endl;
}
std::cout << "MATRIX DATA LOAD SUCCESSFUL..." << std::endl;
std::cout << "Enter 1 to edit a Matrix. Enter 2 to print a Matrix. Enter 3 to clear a Matrix." << std::endl;
short userChoice = 0;
std::cin >> userChoice;
}
int x = 0;
if (x < 100)
{
int y = 1;
}
return 0;
}