Skip to main content
GameDev.net gamedev.net
🔒 Locked

not working correctly

Started by demonrealms Apr 27, 2003 at 9:10 AM 1 replies 350+ views
Original Post
demonrealms
demonrealms
Hey, my program just keeps outputting I have an A+ when I real got an A or a C. Here''s the code:
  
float tgrade1;
		float tgrade2;
		ifstream file_10("ptsposs.txt");
		file_10 >> tgrade1;
		file_10.close();
		ifstream file_11("ptsearned.txt");
		file_11 >> tgrade2;
		file_11.close();
		int tgrade3 = (tgrade2) / (tgrade1) * 100;
		int tgrade4 = tgrade3;
		ofstream file_12("grade.html", ios::app);
		file_12 << "</table>" << endl
			<< "<table align=center>" << endl
			<< "<tr>" << endl
			<< "<td>" << endl
			<< "Total Score: " << tgrade3 << "<br>" << endl
			<< "</td>" << endl
			<< "</tr>" << endl
			<< "</table>" << endl;
		file_12.close();
		if(tgrade4 <= 96)
		{
			ofstream file_13("grade.html", ios::app);
			file_13 << "<div align=center><h4>You got an A+</h4></div>" << endl;
			file_13.close();
			return(main());
		}
		else if(tgrade4 == 95)
		{
			ofstream file_13("grade.html", ios::app);
			file_13 << "<div align=center><h4>You got an A</h4></div>" << endl;
			file_13.close();
			return(main());
		}
		else if(tgrade4 <= 90 && tgrade4 >= 94)
		{
			ofstream file_13("grade.html", ios::app);
			file_13 << "<div align=center><h4>You got an A-</h4></div>" << endl;
			file_13.close();
			return(main());
		}  
Why is it saying I have an A+ if I have an A or below?
CWizard
CWizard

if(tgrade4 <= 96) {} // A+
else if(tgrade4 == 95) {} // A
else if(tgrade4 <= 90 && tgrade4 >= 94) {} // A-

To be sure, you''ll never get an A- with this. That will only happen when your grade is less or equal to 90 and at the same time more or equal to 94. I think you should try to switch the direction of the arrows :

if(tgrade4 >= 96) {} // A+
else if(tgrade4 == 95) {} // A
else if(tgrade4 >= 90 && tgrade4 <= 94) {} // A-



Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.