i think my program is running twice , im not sure why , in my data file i have "2" and my result is "Your total is 4"
why is my program running twice even though i have while(!ins.eof())
// Write a program that scores a blackjack hand
// goal is to get a score as close to 21
// without going over 21
// going over 21 is called "busted"
// card values 2 through 10
// jack, queen, king and ace represented by
// t , j , q , k , a
#include<iostream>// allows user input/output
#include<conio.h>
#include<fstream>//data file / result file
#include<iomanip>
#include<cmath> // math function
#define in_file "data.txt"
#define out_file "result.txt"
usingnamespace std;
char choice;
void blackjackhand();
int main ()
{
blackjackhand();
}
void blackjackhand()
{
ifstream ins; //ins as input stream
ofstream outs; //outs as output stream
ins.open(in_file); //open files
outs.open(out_file);
int value = 0;
int total = 0;
while (!ins.eof())
{
ins >> choice;
switch (choice)
{
case'2':
value = 2;
total = total + value;
break;
case'3':
value = 3;
total = total + value;
break;
case'4':
value = 4;
total = total + value;
break;
case'5':
value = 5;
total = total + value;
break;
case'6':
value = 6;
total = total + value;
break;
case'7':
value = 7;
total = total + value;
break;
case'8':
value = 8;
total = total + value;
break;
case'9':
value = 9;
total = total + value;
break;
case't':
value = 10;
total = total + value;
break;
case'j':
value = 10;
total = total + value;
break;
case'q':
value = 10;
total = total + value;
break;
case'k':
value = 10;
total = total + value;
break;
case'a':
value = 11;
total = total + value;
if (total > 21)
{
value = 1;
}
break;
} // end switch statement
}
if (total <= 21)
{
outs << "Your total is " << total << endl;
}
elseif (total > 21)
{
outs << "Busted" << endl;
}
}