943,771 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5814
  • C++ RSS
Apr 18th, 2004
0

help for program involving switch loops and file

Expand Post »
I'm a novice programmer, I'm writing a program called GPA that reads characters and numbers from a file. The numbers from the file are the amount of credits for a course, the characters on the program represent the grade for the course. I'm supposed to find the amount of credit points by multiplying the credits by the amount of points a grade is worth, for example A=4, B=3 C=2, D=1, F=0. I have to do this by using a file a loops and a switch statement.
email: xadeolax@cs.com
Attached Files
File Type: txt GPA1.txt (1.2 KB, 55 views)
Last edited by frosticex; Apr 18th, 2004 at 12:13 am. Reason: adding email address
Reputation Points: 10
Solved Threads: 0
Newbie Poster
frosticex is offline Offline
2 posts
since Apr 2004
Apr 18th, 2004
0

Re: help for program involving switch loops and file

sounds like homework, try it out your self, post soem code and ill be glad to help.
Reputation Points: 28
Solved Threads: 9
Posting Whiz in Training
BountyX is offline Offline
222 posts
since Mar 2004
Apr 19th, 2004
0

Re: help for program involving switch loops and file

I left an attachement with the post, but here it is again. Please help.

#include<fstream.h>
void main()
{ifstream gpa;
char letterGrade;
int credits=0;
int creditsArray[]={credits};
int totCredits=0;
int creditPoints=0;
int totCreditPoints=0;
int count=0,Points;


gpa.open("C:/Multimedia Files/My Documents/c++/files/gpa1.txt");
if(gpa.fail())
cout<<"Couldn't open the file!!!\n";
else
{
gpa>>letterGrade;
gpa>>credits;
while(!gpa.eof())
{count++;

totCredits+=credits;

cout<<letterGrade;
cout<<credits<<"\n";
gpa>>letterGrade;
gpa>>credits;
switch(letterGrade)
{

case 'A': Points=4;creditPoints=Points*credits;break;
case 'B': Points=3;creditPoints=Points*credits;break;
case 'C': Points=2;creditPoints=Points*credits;break;
case 'D': Points=2;creditPoints=Points*credits;break;
case 'F': Points=0;creditPoints=Points*credits;break;

default: cout<<"Invalid letter grade in file\n";

}//switch

totCreditPoints+=creditPoints;
}//while(!gpa.eof())

gpa.close();


cout<<"Total credits "<<totCredits<<endl;
cout<<"total credit points "<<totCreditPoints<<endl;

if(totCredits=0) cout<<"The GPA can't be calculated!!!\n";


}//else



}//main
Last edited by frosticex; Apr 19th, 2004 at 10:35 am. Reason: inseting code
Reputation Points: 10
Solved Threads: 0
Newbie Poster
frosticex is offline Offline
2 posts
since Apr 2004

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: ASCII to BINARY, & VICA VERCA
Next Thread in C++ Forum Timeline: Circle class





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


Follow us on Twitter


© 2011 DaniWeb® LLC