PDA

View Full Version : Little help on c++ while - switch structures


morgue
10-16-2003, 10:24 PM
Can someone tell me why this isn't working?
I can't compile, when I get to compile it freezes on 'linking...'
I'm using Visual C++ 6

#include <iostream.h>

int main()
{
int grade,
aCount = 0,
bCount = 0;

cout << "Enter the letter grandes." << endl
<< "Enter the EOF character to end input." << endl;

while ( ( grade = cin.get() ) != EOF)
{

switch ( grade )
{

case 'A':
case 'a':
aCount++;
break;

case 'B':
case 'b':
bCount++;
break;

default:
cout << "Incorrect. Enter a new grade." << endl;
break;

}

}

cout << "\n\nTotals for each letter grade are: "
<< "\nA: " << aCount
<< "\nB: " << bCount << endl;

return 0;
}

Jason
10-16-2003, 10:46 PM
interesting code...wouldn't think to do it like that....use the getChar() command...

#include <iostream.h>

int main()
{
int grade, aCount = 0, bCount = 0;

//define the EOF character
cout<<"continue to enter grades finnish with the EOF ";
cout <<"character to end input." << endl;
while (grade != EOF){

cout << "Enter the letter grandes." << endl;


cin>>grade

switch ( grade )
{

//this is sloppy look up libraries to do toUpperCase
case 'A':
case 'a':
aCount++;
break;

case 'B':
case 'b':
bCount++;
break;

default:
cout << "Incorrect. Enter a new grade." << endl;
break;

}

}

cout << "\n\nTotals for each letter grade are: "
<< "\nA: " << aCount
<< "\nB: " << bCount << endl;

return 0;
}


something like that....


Jason

morgue
10-16-2003, 10:54 PM
wtf
it freezes on:
Compiling...
case.cpp

i think i'll reinstall visual studio

good_omen
10-23-2003, 04:20 AM
from experience i will say that Visual C++ sux0rs badly. My personaly favorite C editor/compiler is 'Dev-C++', made by Bloodshed software. i would suggest trying that out, just go to www.bloodshed.net (or is it .org?).