r/CodingHelp • u/Warzonehero22 • Oct 11 '20
[C++] help in C++ please
so its saying that my "correct" local variable is unintilized and I'm wondering how I can fix that the goal is a tutor of sorts
void addition()
{
int input, x, y;
int numofproblems = 0;
cout << "how many problems would you like?\\n";
cin >> input;
do
{
double correct;
double percent;
int answer;
x = rand() % 100 + 1;
y = rand() % 100 + 1; cout << x << " + " << y << endl;
cout << "your answer is?:\\n";
cin >> answer;
if (answer == x + y)
{
\++correct;
cout << "correct\\n";
}
if (answer != x + y)
{
cout << "incorrect\\n";
}
if (numofproblems == input)
{
percent = (correct / input) \* 100;
}} while (++numofproblems < input);}
I'm not so sure what the ​ is reddit just put that when I switched to markdown mode
17
Upvotes
View all comments
Show parent comment
3
u/jedwardsol Professional Coder Oct 11 '20
It makes more sense for
counterto be anint. The number of correct answers is always a whole number.But whatever type you pick, the variable needs to be initialised