I am currently making a program which asks the user to input 10 integers and the code will have to count how many odd numbers there are. At the end of the program it prompts the user whether to retry it again, essentially in a loop if they choose to input a new set of 10 integers.
int i, value;
int odd = 0;
char option;
do
{
for (i=1;i<=10;++i)
{
cout << "Enter integer no. " << i << ": ";
cin >> value;
if (value % 2 == 1)
{
odd++;
}
}
cout << "\nThere are " << odd << " odd numbers.\n";
cout << "\nDo you want to try again? \nEnter Y for Yes and N for No: ";
cin >> option;
if (option == 'N')
{
cout << "\nThank you for using this program. \nProgram Terminating!";
break;
}
} while (option == 'Y');
return 0;
My problem is that the counted and displayed odd numbers on the previous count is added to the next count in the loop. If the previous count had 5 odd numbers and the next count had 4 odd numbers, it would then display a total of 9 odd numbers. How do I separate the count of odd numbers without them adding up with each other with every new input of 10 integers?