944,206 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 583
  • C++ RSS
Oct 28th, 2007
0

Total_grade

Expand Post »
Im doing a program that asks to enter a student's grades on four exams, I have to display the four grades and the average of the four grades, to the nearest tenth. The most problem im having is using the variable call total_grade which i have to initialize to zero.
cpp Syntax (Toggle Plain Text)
  1. #include < iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int exam 1, // Exam 1 grade
  9. exam 2, // Exam 2 grade
  10. exam 3, // Exam 3 grade
  11. exam 4; // Exam 4 grade
  12. double averagr; // Average of the four exam grades
  13. // Setup output stream for one decimal place
  14. cout << setpresion(1)
  15. << setiosflags(ios::fixed)
  16. << setiosflags(ios::showpoint);
  17.  
  18. cout << "Enter the grade for Exam 1: ";
  19. cin >> 100
  20. cout << "Enter the grade for Exam 2: ";
  21. cin >> 84
  22. cout << "Enter the grade fot Exam 3: ";
  23. cin >> 78
  24. cout << "Enter the grade for Exam 4: ";
  25. cin >> 94
  26.  
  27. // This program asks the user to enter a student
  28. // grades on four exams and display the for grades
  29. // and the average of four exams rounded to the
  30. // nearest tenth.
  31.  
  32. total_grade=double (exam1 + exam2+ exam3 + exam4)/4;
  33. cout << endl;
  34. cout << "The average of the four exams is " << average << endl;
  35. return 0;
  36. }
Last edited by WaltP; Oct 28th, 2007 at 1:30 pm. Reason: Added CODE tags -- you actually typed right over how to use them when you entered this post...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
navy2005 is offline Offline
2 posts
since Oct 2007
Oct 28th, 2007
0

Re: Total_grade

Quote ...
cout << "Enter the grade for Exam 1: ";
cin >> 100
//...
I assume what you want is to have those as the inputs, right? That doesn't work. You can't read in a number like that. What you're going to have to do is read in a variable and when you run the program the variable is assigned the number you type in (see below).

>> int exam 1
You can't do that either. Variables cannot have spaces in their name. int exam_1 is more what you want. Or you can do what you did later on in your code and call them exam1, exam2 etc.

cpp Syntax (Toggle Plain Text)
  1. int grade_1;
  2. cout<< "Enter grade for exam: ";
  3. cin> >grade_1;
  4.  
  5. cout<< "You entered: " << grade_1;

The rest looks OK.
Reputation Points: 453
Solved Threads: 57
Posting Virtuoso
twomers is offline Offline
1,873 posts
since May 2007
Oct 29th, 2007
0

Re: Total_grade

thank you so much im taking a online class for C++ and some of the material i wasnt familar with
Reputation Points: 10
Solved Threads: 0
Newbie Poster
navy2005 is offline Offline
2 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: operator-
Next Thread in C++ Forum Timeline: help! how to implement a copy constructor in c++ for ADT queues??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC