I'm trying to write an array in c++, which consist of 10 integers that are all 1, unless changed through keyboard input. For some reason my code prints out way more than 10 integers and I'm not sure why.
int main()
{
int index, value;
int count = 0;
int myData [10];
for (int i = 0; i < sizeof(myData); i++)
{
myData[i] = 1;
}
do
{
for (int i = 0; i < sizeof(myData); i++)
{
std::cout << myData[i] << " ";
}
std::cout << "Input index: ";
std::cin >> index;
std::cout << "Input value: ";
std::cin >> value;
myData[index] = value;
} while ((0 <= index) && (index <= sizeof(myData)));
std::cout << "Index out of range. Exit." << std::endl;
return 0;
}
EDIT I got it to work thank you :D but for some reason now I'm getting a buffer overflow. Anyway to fix this?