Originally Posted by
todouble22
first off if you're going to do it this way, you will have to satisfy the rest of the possible answers in your if statements. You have one for your 100% answer. Think of the other scenarios that you have. and give that a try
Ah, thanks, something like this you mean?
Code:
#include<iostream>
using namespace std;
int main ()
{
int add;
int sub;
int div;
int counter=0
cout << "Whats 2 + 2? ";
cin >> add;
cout << "Whats 2 - 2? ";
cin >> sub;
cout << "Whats 20 / 4? ";
cin >> div;
if (add == 4 && sub == 0 && div == 5)
{
cout << "Your score is 100%!\n" ;
}
else
{
if (add == 4 && sub == 0)
{
cout << "Your score is 66%! \n";
}
else
{
if (add == 4)
{
cout << "Your score is 33%! \n";
}
else
{
if (add == 4 && div == 5)
{
cout << "Your score is 66%! \n";
}
else
{
if (div == 5)
{
cout << "Your score is 33%! \n";
}
else
{
if (sub == 0)
{
cout << "Your score is 33%! \n";
}
else
{
if (sub == 0 && div == 5)
{
cout << "Your score is 66%! \n";
}
else
{
cout << "Your score is 0%!\n";
}
}
}
}
}
system("Pause");
return 0;
}
}
}
Originally Posted by
Oldman47
Create a counter in lieu of the numerous if statements. IE., int counter=0; Each time an answer is correct, do ++counter; At the end of your Q & A, compare the counter count to the number of questions asked.
So, if you asked 3 and your counter say you've answered 1 correct, well, do the math. There's an operand that can compute the percentage.
Sorry for my nubness, I don't understand what you mean, do you mean something like this?
Code:
#include<iostream>
using namespace std;
int main ()
{
int add;
int sub;
int div;
int counter = 0;
cout << "Whats 2 + 2? ";
cin >> add;
cout << "Whats 2 - 2? ";
cin >> sub;
cout << "Whats 20 / 4? ";
cin >> div;
if (add == 4)
{
++counter;
}
else
{
if (sub == 0)
{
++counter;
}
else
{
if (add == 4)
{
++counter;
}
else
{
if (div == 5)
{
++counter;
}
else
{
cout << "Your score is 0%!\n";
}
}
}
}
system("Pause");
return 0;
}
Only I don't know how to use the counter to output the percentage though.