I have a problem with some code I am trying to right in c++, it's the average of 3 test scores and the cout will give you your average but then it needs a bool variable if the average is equal to 100% then true it will display a string of "Congrats you received a perfect" and if it's not 100% nothing will appear besides their average, but I keep getting the string of "Congrats" to come up even if the average is not 100%
#include <iostream>
using namespace std;
int main ()
{
int score1, score2, score3;
cout << "Enter your 3 test scores and I will \n";
cout << "average them: ";
cin >> score1 >> score2 >> score3 ;
double average;
average = (score1 + score2 + score3) / 3.0;
cout << "Your average is " << average << endl;
bool perfectScore;
if(average = 100)
perfectScore = true;
else
perfectScore = false;
if(perfectScore == true)
cout << "Congratulations! \n";
cout << "That's a perfect score. \n";
cout << "you deserve a pat on the back! \n";
return 0;
}
Aucun commentaire:
Enregistrer un commentaire