|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
end-of-line problem
I've been having trouble getting this code to start a tally of the sum of
one line then go on to the next. The program tallys up a row of cards in a blackjack hand that's in a file and ouputs the hand plus the total or if it was a bust in a new file. Thanks! #include <fstream> #include <iostream> using namespace std; int main() { char card; ifstream fin; //declares object fin of class ifstream ofstream fout; //declares object fout of class ofstream fin.open("hand.txt"); //opens file and associates it with object fin fout.open("score.txt"); //opens file and associates it with object fout fin>>card; while (! fin.eof()) //continues while until at the end of the file { int tot = 0; while (card != '/n') { fout<<card; int card2; switch (card) //calls switch function { case '2': card2 = 2; break; case '3': card2 = 3; break; case '4': card2 = 4; break; case '5': card2 = 5; break; case '6': card2 = 6; break; case '7': card2 = 7; break; case '8': card2 = 8; break; case '9': card2 = 9; break; case 't': card2 = 10; break; case 'T': card2 = 10; break; case 'j': card2 = 10; break; case 'J': card2 = 10; break; case 'q': card2 = 10; break; case 'Q': card2 = 10; break; case 'k': card2 = 10; break; case 'K': card2 = 10; break; case 'a': case 'A': if (tot < 11) card2 = 11; else card2 = 1; break; default: cout<<"An unacceptable character is in the hand."; } tot = tot + card2; cout<<tot; fin.get(card); while (isspace(card)) { if (card != '/n') fin.get(card); else break; } } if (tot <= 21) fout<<" "<<tot<<endl; else fout<<" BUSTED."<<endl; } fin.close(); //closes file fout.close(); return 0; } |
|
#2
|
|||
|
|||
|
you have '/n' in your code instead of '\n' change all this.
the new line character is '\n' NOT '/n' |
|
#3
|
|||
|
|||
|
wow, i guess i was way too tired
|
|
#4
|
|||
|
|||
|
no problem, btw can you send me an example hand.txt file? I dont know how black jack is played
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > end-of-line problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|