General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 7th, 2003, 12:50 AM
dmagic dmagic is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 dmagic User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to dmagic
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;
}

Reply With Quote
  #2  
Old November 7th, 2003, 01:31 AM
h2c357 h2c357 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 h2c357 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
you have '/n' in your code instead of '\n' change all this.
the new line character is '\n' NOT '/n'

Reply With Quote
  #3  
Old November 7th, 2003, 01:33 AM
dmagic dmagic is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 dmagic User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to dmagic
wow, i guess i was way too tired

Reply With Quote
  #4  
Old November 7th, 2003, 01:39 AM
h2c357 h2c357 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 2 h2c357 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
no problem, btw can you send me an example hand.txt file? I dont know how black jack is played

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > end-of-line problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway