this is the program so far:
#include <iostream.h>
#include <iomanip.h>
main()
{
char a,b,c,d,character_entered;
int i,g;
float f;
i=0;
cout << "Welcome. Enter the answer that fits best." << '\n';
cout << '\n';
cout << '\n';
cout << "Question 1";
cout << '\n';
cout << '\n';
cout << "3(10+6)" << '\n';
cout << "a. 48" << '\n';
cout << "b. 32" << '\n';
cout << "c. 54" << '\n';
cout << "d. 68" << '\n';
cin >> character_entered;
switch (character_entered)
{
case 'a':
cout << "Your right!" << '\n';
break;
case 'b':
cout << "Wrong answer the correct answer is a." << '\n';
break;
case 'c':
cout << "Wrong answer the correct answer is a." << '\n';
break;
case 'd':
cout << "Wrong answer the correct answer is a." << '\n';
break;
default:
cout << "Illegal entry." << '\n'
;
break;
}
if (character_entered = a)
i++;
else
i;
cout << '\n';
cout << '\n';
f = i/20;
g = f*100;
cout << '\n';
cout << '\n';
cout <<fixed<<setprecision(0)<<g<< "%";
cout << '\n';
cout << '\n';
system ("PAUSE");
return 0;
}
I use dev-c++ 4.9.9.2, the out put is always 0% at the end even when I answer all the questions right so what am i doing wrong? (this is just some of it couldnt fit the whole program in)
Please don't. The compiler it comes with is horribly out of date. Your code above will not compile on a modern, correct C++ compiler (because it is not correct C++).
if (character_entered = a)
Did you mean if (character_entered == a)?
1 2
else
i;
What is that supposed to do? It does nothing.
f = i/20;
i is an int. An int divided by another int will give you an int. At this point, f is set to zero. If you want f to not be zero, do not divide an int by another int.
even though you've defined f as a floating point, you're using integer division (int i/20) which always results in an integer. So unless i is more than 20 the result is 0.
sorry it is the compiler my teacher is making me use.
You have my sympathies.
didn't work
Changing f = i/20; to f = i/20.0; works on my machine. Maybe you didn't make the change, or didn't save it, or didn't recompile it, or didn't enter "a" as the input.