Hello,
I started making a program that would convert your test results into a percentage, making snide remarks on your grade. I ran it through codepad.org, and I got an error at line 18, which was a blank space. Here's the code itself:
#include <iostream>
int main()
{
do
{
bool onemore;
onemore == true;
char yesno;
yesno == 'y';
float total;
std::cout << "What was the test out of? ";
std::cin >> total;
float mark;
std::cout << "What did you get? ";
std::cin >> mark;
float totalonehundred;
totalonehundred == (mark / total) * 100;
if (totalonehundred >= 100.01)
std::cout << "\nNice try, Putin.\n";
if (totalonehundred >= 60 )
{
if (totalonehundred >= 75)
{
if (totalonehundred >= 85)
{
if (totalonehundred >= 95)
{
if (totalonehundred ==100)
{
std::cout << "\nYou star student you. You got "<<totalonehundred << " Percent!\n";
return 0;
}
std::cout << "\nNoice. You got " << totalonehundred << " percent.\n";
return 0;
}
std::cout << "\nYou're good. You got "<<totalonehundred << " percent. On our way to high math, eh?\n";
return 0;
}
std::cout << "\nLooks like you got "<<totalonehundred << " percent. Not bad, but you could do better.\n";
return 0;
}
std::cout << "\nYeesh, you got "<<totalonehundred << " percent. Cutting it close, aren't we?\n";
return 0;
}
if (totalonehundred <=60)
std::cout << "\n You got " <<totalonehundred << " percent. \nThat\n is\n a\n FAIL!\n";
std::cout << "\n Start over? Y/N \n";
std::cin >> yesno;
if ( yesno == 'y')
{ onemore == true;
return 0;
}
if ( yesno == 'n')
{ onemore == false;
}
while (onemore != 'flase')
}
It's been driving me absolutely bonkers. It's probably super-obvious too, I'm just not seeing it at the moment. If you could help me out, I would be much obliged!
#include <iostream>
int main()
{
do
{
bool onemore;
onemore == true;
char yesno;
yesno == 'y';
float total;
std::cout << "What was the test out of? ";
std::cin >> total;
float mark;
std::cout << "What did you get? ";
std::cin >> mark;
float totalonehundred;
totalonehundred = (mark / total) * 100;
if (totalonehundred >= 100.01)
std::cout << "\nNice try, Putin.\n";
if (totalonehundred >= 60 )
{
if (totalonehundred >= 75)
{
if (totalonehundred >= 85)
{
if (totalonehundred >= 95)
{
if (totalonehundred =100)
{
std::cout << "\nYou star student you. You got "<<totalonehundred << " Percent!\n";
return 0;
}
std::cout << "\nNoice. You got " << totalonehundred << " percent.\n";
return 0;
}
std::cout << "\nYou're good. You got "<<totalonehundred << " percent. On our way to high math, eh?\n";
return 0;
}
std::cout << "\nLooks like you got "<<totalonehundred << " percent. Not bad, but you could do better.\n";
return 0;
}
std::cout << "\nYeesh, you got "<<totalonehundred << " percent. Cutting it close, aren't we?\n";
return 0;
}
if (totalonehundred <=60)
std::cout << "\n You got " <<totalonehundred << " percent. \nThat\n is\n a\n FAIL!\n";
std::cout << "\n Start over? Y/N \n";
std::cin >> yesno;
if ( yesno = 'y')
{ onemore = true;
return 0;
}
if ( yesno = 'n')
{ onemore = false;
}
while (onemore != 'flase')
}
But now it's giving me this:
Line 18: error: character constant too long for its type
cc1plus: warnings being treated as errors
In function 'int main()':
Line 39: warning: suggest parentheses around assignment used as truth value
Line 77: warning: suggest parentheses around assignment used as truth value
Line 82: warning: suggest parentheses around assignment used as truth value
Line 88: error: expected primary-expression before '}' token
compilation terminated due to -Wfatal-errors.
#include <iostream>
int main()
{
do
{
bool onemore;
onemore = true;
char yesno;
yesno = 'y';
float total;
std::cout << "What was the test out of? ";
std::cin >> total;
float mark;
std::cout << "What did you get? ";
std::cin >> mark;
float totalonehundred;
totalonehundred = (mark / total) * 100;
if (totalonehundred >= 100.01)
std::cout << "\nNice try, Putin.\n";
if (totalonehundred >= 60 )
{
if (totalonehundred >= 75)
{
if (totalonehundred >= 85)
{
if (totalonehundred >= 95)
{
if (totalonehundred =100)
{
std::cout << "\nYou star student you. You got "<<totalonehundred << " Percent!\n";
return 0;
}
std::cout << "\nNoice. You got " << totalonehundred << " percent.\n";
return 0;
}
std::cout << "\nYou're good. You got "<<totalonehundred << " percent. On our way to high math, eh?\n";
return 0;
}
std::cout << "\nLooks like you got "<<totalonehundred << " percent. Not bad, but you could do better.\n";
return 0;
}
std::cout << "\nYeesh, you got "<<totalonehundred << " percent. Cutting it close, aren't we?\n";
return 0;
}
if (totalonehundred <=60)
std::cout << "\n You got " <<totalonehundred << " percent. \nThat\n is\n a\n FAIL!\n";
std::cout << "\n Start over? Y/N \n";
std::cin >> yesno;
if ( yesno = 'y');
{ onemore = true;
return 0;
}
if ( yesno = 'n');
{ onemore = false;
return 0;
}
while (onemore != false)
}
Now it says:
cc1plus: warnings being treated as errors
In function 'int main()':
Line 39: warning: suggest parentheses around assignment used as truth value
Line 74: warning: suggest parentheses around assignment used as truth value
Line 79: warning: suggest parentheses around assignment used as truth value
Line 86: error: expected primary-expression before '}' token
compilation terminated due to -Wfatal-errors.
So I tested a slightly tweaked version of Lethal's code, and it seemed to work only when I failed a test. I noticed that when I have it make a comment, at the end it says
return 0;
. That might be stopping it from activating the "start over?" loop. I got rid of it, and here is the code now:
#include <iostream>
int main()
{
bool onemore;
do
{
onemore = true;
char yesno;
yesno = 'y';
float total;
std::cout << "What was the test out of? ";
std::cin >> total;
float mark;
std::cout << "What did you get? ";
std::cin >> mark;
float totalonehundred;
totalonehundred = (mark / total) * 100;
if (totalonehundred >= 100.01)
{ std::cout << "\nNice try, Putin.\n";
}
if (totalonehundred >= 60 )
{
if (totalonehundred >= 75)
{
if (totalonehundred >= 85)
{
if (totalonehundred >= 95)
{
if (totalonehundred =100)
{
std::cout << "\nYou star student you. You got "<<totalonehundred << " Percent!\n";
}
std::cout << "\nNoice. You got " << totalonehundred << " percent.\n";
}
std::cout << "\nYou're good. You got "<<totalonehundred << " percent. On our way to high math, eh?\n";
}
std::cout << "\nLooks like you got "<<totalonehundred << " percent. Not bad, but you could do better.\n";
}
std::cout << "\nYeesh, you got "<<totalonehundred << " percent. Cutting it close, aren't we?\n";
}
if (totalonehundred <=60)
{std::cout << "\n You got " <<totalonehundred << " percent. \nThat\n is\n a\n FAIL!\n";
}
std::cout << "\n Start over? Y/N \n";
std::cin >> yesno;
if ( yesno == 'y'){
onemore = true;
}
if ( yesno == 'n'){
onemore = false;
return 0;
}
}
}while (onemore != false);
}
But, of course, it couldn't be that simple. Now it complains like this:
prog.cpp: In function 'int main()':
prog.cpp:87: error: expected `while' before '}' token
prog.cpp:87: error: expected `(' before '}' token
prog.cpp:87: error: expected primary-expression before '}' token
prog.cpp:87: error: expected `)' before '}' token
prog.cpp:87: error: expected `;' before '}' token
prog.cpp: At global scope:
prog.cpp:87: error: expected unqualified-id before 'while'
prog.cpp:88: error: expected declaration before '}' token
Any ideas?
Note: when I said 'work' at the top, I meant: do the calculation, give you the percent, snide comment, then it asks for another test. If 'y' was entered, it would start over. if 'n' was entered, it would close.