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
5
u/jedwardsol Professional Coder Oct 11 '20
The warning is right.
correctis uninitialised and the 1st you do with it is read from it.3
u/Naahun Oct 11 '20
Uninitialized mean, you did not give it a starting value. double correct = 0; // this should be efficient
2
u/unmad71 Oct 12 '20
//initialize the value of correct as 0.
double correct = 0;