if, else if statement problem

Hi! I'm beginning to write some C++ programs as a hobby.
However i encounter a problem when i tried the beginner excercise "The Grading Program". No matter what i enter as my testscore, it tells me i have earned a perfect score, and why it does it is above me. Could you take a look?

#include <iostream>
using namespace std;
int main(void)
int testScore;
cout << "Enter your test score!" << endl;
cin >> testScore;

if (testScore = 100)
cout << "You got a perfect score!" << endl;
else if (testScore >= 90)
cout << "You got an A!" << endl;
else if (testScore >= 80)
cout << "You got a B!" << endl;
else if (testScore >= 70)
cout << "You got a C!" << endl;
else if (testScore >= 60)
cout << "You got a D!" << endl;
else if (testScore >=59)
cout << "You got an F!" << endl;

return 0;
if (testScore = 100) this assigns 100 to testScore
if (testScore == 100) (==) this checks if the two values are the same
Because you always assign yourself the perfect score.:) Maybe it is a good idea, is not it?:)
Last edited on
Topic archived. No new replies allowed.