| | |
Total_grade
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2007
Posts: 2
Reputation:
Solved Threads: 0
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)
#include < iostream> #include <iomanip> using namespace std; int main() { int exam 1, // Exam 1 grade exam 2, // Exam 2 grade exam 3, // Exam 3 grade exam 4; // Exam 4 grade double averagr; // Average of the four exam grades // Setup output stream for one decimal place cout << setpresion(1) << setiosflags(ios::fixed) << setiosflags(ios::showpoint); cout << "Enter the grade for Exam 1: "; cin >> 100 cout << "Enter the grade for Exam 2: "; cin >> 84 cout << "Enter the grade fot Exam 3: "; cin >> 78 cout << "Enter the grade for Exam 4: "; cin >> 94 // This program asks the user to enter a student // grades on four exams and display the for grades // and the average of four exams rounded to the // nearest tenth. total_grade=double (exam1 + exam2+ exam3 + exam4)/4; cout << endl; cout << "The average of the four exams is " << average << endl; return 0; }
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...
•
•
•
•
cout << "Enter the grade for Exam 1: ";
cin >> 100
//...
>> 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)
int grade_1; cout<< "Enter grade for exam: "; cin> >grade_1; cout<< "You entered: " << grade_1;
The rest looks OK.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: operator-
- Next Thread: help! how to implement a copy constructor in c++ for ADT queues??
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion convert count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






