something wrong with the looping
Apr 12, 2014 at 1:10pm UTC
hi guys..
when running these codes, works fine until "Enter how many subjects: "..when i input '1' for example it will ask name of subject, how many credits for the subject, Quality Points for the subject like i wanted it to be..but after inputting values for the three prompts it will back again to "Enter how many subjects: "..there's something wrong there but i can't seem to identify the error..anyone have any clue?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
// File Header
#include <iostream>
#include <string>
using namespace std;
void intro();
void menu();
double subcred();
int main()
{ string name;
string ID;
string Inst;
string prog;
double GPA;
intro();
cout<< "Enter name:" ;
cin>>name;
cout<<"Enter ID:" ;
cin>>ID;
cout<<"Enter Institute:" ;
cin>> Inst;
cout<<"Enter Program:" ;
cin>>prog;
subcred();
GPA = subcred();
cout<< "GPA = " << GPA << endl;
system("pause" );
return 0;
}
void intro(){
cout << "\n\n\n\n\n\n\n" ;
cout << "\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n" ;
cout << "\t* Welcome To Student Exam Information System *\n" ;
cout << "\t* *\n" ;
cout << "\t* This Program Developed By *\n" ;
cout << "\t* Iqmal Azim & Khairul Aiman *\n" ;
cout << "\t* *\n" ;
cout << "\t* *\n" ;
cout << "\t* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n" ;
}
void menu(){
system("cls" );
cout << "Main Menu" << endl;
}
double subcred()
{ double GPA,qp[50],totalqp=0,totalcred=0;
int i, subject, credit[50];
string subname[100];
cout<< "Enter how many subjects: " ;
cin>>subject;
for (i=0; i<subject; i++)
{ cout<<"================================================" <<endl;
cout<< "name of subject [" <<i+1<< "] = " ;
cin>>subname[i];
cout<< "how many credits for the subject? = " ;
cin>>credit[i];
cout<<"Quality Points for the subject? = " ;
cin>>qp[i];
totalqp += qp[i];
totalcred +=credit[i];
cout<<"================================================" <<endl;
}
GPA = totalqp/totalcred;
return GPA;
}
Apr 12, 2014 at 2:05pm UTC
Delete lines 28-30 and try this:
cout<< "GPA = " << subcred() << endl;
Apr 12, 2014 at 2:17pm UTC
that fixed it! thanx!
Topic archived. No new replies allowed.