So, this is my very first questions on Stack Overflow. I'm in the process of learning C++ after some hard-fought experience with MATLAB. I've got a simple exercise that builds fine, but does not produce the expected result.
I get no errors, either. I'm running Xcode 5.
I suspect the problem has something to do with the initialization of my variables. When I look into debugging, my variables stay set to 0.
#include <iostream>
using namespace std;
int main()
{
//Declare variables
int score = 0;
//input score
cout << "Emter score: ";
cin >> score;
if (score == 100)
{
cout << "Final Score: " << score;
cout << "You received a perfect score! \n";
// 100% is an A.
}
else if ((score >= 90) && (score <= 100))
{
cout << "Final Score: " << score;
cout << "Your grade is an A. Nice Job! \n";
// 90-100 is an A.
}
else if ((score >= 80) && (score <= 89))
{
cout << "Final Score: " << score;
cout << "Your grade is a B. Well done. \n";
// 80-89 is a B.
}
else if ((score >= 70) && (score <= 79))
{
cout << "Final Score: " << score;
cout << "Your grade is a C. Really? \n";
// 70-79 is a C.
}
else if ((score >= 60) && (score <= 69))
{
cout << "Final Score: " <<score;
cout << "Your grade is a D. You suck. Seriously. \n";
// 60-69 is a D.
}
else if ((score >= 0) && (score <= 59))
{
cout << "Final Score: " << score;
cout << "You got an F! YOU FAIL! GO JUMP OUT THE WINDOW. \n";
// 0-59 is an F.
}
return 0;
}
Sorry for the long post, I did not want to leave anything out. Thanks again.
ETA: Fixed the newline characters. I retyped the code in line for line and it ran just fine. I suspect it had something to do with the way all this stuff was being cast, but I'm not sure.