Total_grade

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2007
Posts: 2
Reputation: navy2005 is an unknown quantity at this point 
Solved Threads: 0
navy2005 navy2005 is offline Offline
Newbie Poster

Total_grade

 
0
  #1
Oct 28th, 2007
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.
  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...
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 1,868
Reputation: twomers has a spectacular aura about twomers has a spectacular aura about twomers has a spectacular aura about 
Solved Threads: 56
twomers's Avatar
twomers twomers is offline Offline
Posting Virtuoso

Re: Total_grade

 
0
  #2
Oct 28th, 2007
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.

  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.
I blag!?
"Mr Kitty, you have to live in the attic now. Here, write a diary."
I am the Walrus!
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 2
Reputation: navy2005 is an unknown quantity at this point 
Solved Threads: 0
navy2005 navy2005 is offline Offline
Newbie Poster

Re: Total_grade

 
0
  #3
Oct 29th, 2007
thank you so much im taking a online class for C++ and some of the material i wasnt familar with
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC