Skip to main content
gamedev.net
🔒 Locked

Not computing right,

Started by demonrealms 2 replies 550+ views
Original Post
demonrealms
demonrealms
Why is this not working? I wan it where you enter a two numbers and it divides them then * 100. Like this Points possible: 80 Points earned: 40 Total score: %50 But it just puts out the first number. Heres the code:
  
cout << "Lesson/Test name: ";
		cin.getline(lname, 60);
		cout << "Points possible: ";
		cin.getline(pts1, 8);
		ofstream file_01("num1.txt");
		file_01 << pts1;
		file_01.close();
		Sleep(400);
		ifstream file_02("num1.txt");
		file_02 >> grade1;
		file_02.close();
		cout << "Points Earned: ";
		cin.getline(pts2, 8);
		ofstream file_03("num1.txt");
		file_03 << pts2;
		file_03.close();
		ifstream file_04("num1.txt");
		file_04 >> grade2;
		file_04.close();
		int fgrade = grade1;
		int fgrade2 = grade2;
		int fgrade3 = 100;
		int fgrade4 = (fgrade2 / fgrade) * fgrade3;
		cout << "Your grade average is: " << fgrade << endl;  
Anyone know why?
Sneftel
Sneftel
You're working with integers when you should be working with floating point numbers. Keep in mind that in integer terms, 40 / 80 = 0.

EDIT: also, shouldn't you be outputting fgrade4, not fgrade?


How appropriate. You fight like a cow.

[edited by - sneftel on April 26, 2003 8:16:10 PM]
yaroslavd
yaroslavd
Another thing. You don''t wanna create 5 ostream objects that all refer to one file. First, have the user input all the variables. Then, output them to the file, but use one ostream object. Saves time and memory.

Topic Locked

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

Sign in to reply to this topic.