-
Help!!
I have two assigments due in the morning and I left my book in the computer lab and it's locked up. I think I got the first one done, but the second one I don't know.
Here is the problem.
make a program to allow a student to obtain hes GPA. each class may vary on number of credit hours. therefor there will be 2 inputs, grade and credit hours. promp the student to use a numeric value for thye grade 4 for A, 3 for B and so on. A student may take one or several classes. ID must be an input value. No need to echo input except for ID, but should display the credit hours that the student has earned as well as the GPA.
I did this when I had my book, but I think it is way off. this is our second program and we only know very simple steps. Any help would be great.
#include <iostream>
#include <cctype>
using std::cin;
using std::cout;
int main()
{
int id, mark = 0;
char yesno = 'y';
do {
do {
cout<<"Please enter ID:";
cout<<"Please enter grade: ";
cin>>grade;
cout<<"Please enter credit hours: ";
cin>>mark;
} while ( (mark < 0) && (mark > 100) )
if (mark>=4)
cout<<"Student "<<id<<" got a grade A";
else if (mark>=3)
cout<<"Student "<<id<< " got a grade B";
else if (mark>=3)
cout<<"Student "<<id<< " got a grade C";
else if (mark>=2)
cout<<"Student "<<id<< " got a grade D";
//else if (mark<=2) //
else
cout<<"Student "<<id<< " got a grade F";
cout<<"Again?: ";
cin>>yesno;
} while (toupper(yesno)!='N');
cout<<
return 0
-
To start, it looks like ID is never used, so when you try to run it, you'll come up with garbage when you try to cout the students ID.
Second, take a peek at your while, you probably meant ( (mark < 0) && (mark > 100) )
But if the assignment is to get the GPA, they probably want you to keep track of the total of points(marks), then divide by the number of marks entered.
(ie, 3+4+2+3 = 12, 12/4 = 3, which would be their GPA).
Wynder
-
Ok let me stare at it a while. I so lost without my book. I a "newbie" but I enjoy doing it,,,i think.
-
I think this is all I can do without my book. How wrong is it?
I'm really lost..
Any help with it would be great
-
Code:
#include <iostream>
#include <cctype>
using std::cin;
using std::cout;
int main()
{
int id, mark = 0;
do {
do {
cout<<"Please enter ID:";
cout<<"Please enter grade: ";
cin>>grade;
cout<<"Please enter credit hours: ";
cin>>mark;
} while ( mark < 0 && 100 > mark );
if (mark>=4)
cout<<"Student "<<id<<" got a grade A";
else if (mark>=3)
cout<<"Student "<<id<< " got a grade B";
else if (mark>=3)
cout<<"Student "<<id<< " got a grade C";
else if (mark>=2)
cout<<"Student "<<id<< " got a grade D";
//else if (mark<=2) //
else
cout<<"Student "<<id<< " got a grade F";
cout<<"Again?: ";
}
How's this
[code][/code]tagged by Salem
-
From what i can see, you haven't received an input for the ID, and i think you need to put this in.
Also,
Code:
while ( mark < 0 && 100 > mark );
should be
Code:
while ( mark < 0 || mark > 100 );
if you are repeating it until you get a correct code.