program skipped looping
Apr 12, 2014 at 6:37am UTC
hello, i'm new to this forum and new to C++..need help with this..what will happen is, the program will run but only until "enter how many subjects"..after inputting the number, program will end, skipping the for loop..can u guys point me what's wrong in these codes? thanx~
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
#include <iostream>
#include <string>
using namespace std;
int main()
{
double GPA, qp[50], totalqp = 0, totalcred = 0;
int subject, i, credit[50], counter = 1;
string subname[100];
cout << "Enter how many subjects: " ;
cin >> subject;
for (i = 0; i>subject; i++)
{
cout << "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];
}
GPA = totalqp / totalcred;
system("pause" );
return 0;
}
Apr 12, 2014 at 6:44am UTC
i = 0; i>subject
This would mean it only loops if you have negative numbers. I think you meant less than subject not greater than subject.
Apr 12, 2014 at 6:49am UTC
ahh yes....silly me..thank you very much!
Topic archived. No new replies allowed.