endless input

Its causing me to put in endless input, never outputting anything from the loop, any ideas? I am also going to be spooling out the output, so i know some of it looks unorganized, i just want it to be outputting the right thing before i set up the spool.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

int main()
{
double avgCost, cHours, cost, SSN, students, y, addAmt;
char instate;

cout << "How many students do you have to input?";
cin >> students;
cout << "Please input you social security number, followed by a y\n(for if you live instate)";
cout << "or a n (for if you live out of state),\nand finally type in your credit hours.\n";
y = 0;
avgCost = 0;

cout << "Social Security Number" << " " << "Tution Cost" << " " << "Overall Tution";
{

while (y < students)

cin >> SSN >> instate >> cHours;

{if (instate == 'Y' || instate == 'y')
{if (cHours >= 12)
cost = 1764;
else
cost = cHours + 147;}
else if (cHours >= 12)
cost = 7296;
else
cost = 608 * cHours;}

{if (cHours > 6)
addAmt = 112.50;
else
addAmt = cHours * 18;}

cost = cost + 45 + addAmt;
avgCost = cost + avgCost;

cout << left << setw(25) << SSN << setw(14) << fixed << setprecision(2) << cost;

++y;
}

cout << setw(40) << avgCost;

return 0;
}
Last edited on
I think you misunderstand the use of the curly braces. The belong after the conditional statement (like while, if, etc.) not before.

So correctly used your while statement will look like this:
1
2
3
4
5
6
cout << "Social Security Number" << " " << "Tution Cost" << " " << "Overall Tution";

while (y < students)
{ // Note

cin >> SSN >> instate >> cHours;
okay thank you, ima test it out after class.
Topic archived. No new replies allowed.