Hey so I wrote this blackjack program to read from file but i'm getting these errors on the specified lines:
Error 1 error C2059: syntax error : 'while' line: 46
Error 2 error C2228: left of '.ins' must have class/struct/union line: 48
Error 3 error C2050: switch expression not integral line: 50
Error 4 fatal error C1903: unable to recover from previous error(s); stopping compilation line: 78

I was hoping someone could help me out with these, Thanks

//This is a program that plays the game blackjack. 
//this program reads from file and outputs in a result file
//the input file has the number of cards per round and will calculate the total score of the given round

#include <fstream> 
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <cmath>
using namespace std;

#define in_file "data.txt"
#define out_file "result.txt"

int main()
{
	ifstream ins; //associates ins as an input system
	ofstream outs; // associates outs as an output system

	//declare variables 
	int count; //loop counter
	int count2; // counter for calculating the ace's value
	int numbervalue = 0; //numerical value of card numbers 

	int cardvalue = 0; //numerical value of card
	int totalscore = 0; //total score of player
	int aceidentifier = 0; //identifies if an ace is present
	int acecounter; //counts number of aces
	int loopend = 0; //end of loop
	int charidentifier = 0; //identifies if wrong card is input

	char number; //number of cards
	char cardchar; //character of card ex. face card 

	const int aceelleven = 11; //ace is elleven 
	const int aceone = 1; //ace is one
	const int win = 21; //win if score = 21

	ins.open(in_file);
	outs.open(out_file);

	//program is about to begin

	cout << "The Blackjack Program is starting" << endl. 

	while (loopend != -99); //when to end the loop
	{
		ins >>number; 

		switch (number) 
		{
		case '2':
			numbervalue = 2;
			break;
		case '3':
			numbervalue = 3;
			break;
		case '4':
			numbervalue = 4;
			break;
		case '5':
			numbervalue = 5;
			break;
		default:
			loopend = -99;
			break;

		}
		if (loopend != -99) //identifies the end of the loop
		{
			if ( (2 <= numbervalue) && (5 >= numbervalue) ) //for number of cards

			{
				count = 0;
				count2 = 0;
				acecounter = 0;

				while (count != numbervalue) //loop for adding the cards values

				{
					ins >> cardchar; //read from data.txt

					if ( ((cardchar >= '2') && (cardchar <= '9')) || (cardchar == 'a', 'A', 't', 'T', 'j', 'J', 'q', 'Q', 'k', 'K') ) 

						switch (cardchar) 
					{
						case 'a': case 'A':
							cardvalue = 11;
							aceidentifier = 1;
							acecounter += 1;
							break;

						case '2':
							cardvalue = 2;
							break;

						case '3':
							cardvalue = 3;
							break;

						case '4':
							cardvalue = 4;
							break;

						case '5':
							cardvalue = 5;
							break;

						case '6':
							cardvalue = 6;
							break;

						case '7':
							cardvalue = 7;
							break;

						case '8':
							cardvalue = 8;
							break;

						case '9':
							cardvalue = 9;
							break;

						case 't': case 'T':
							cardvalue = 10;
							break;

						case 'j': case 'J':
							cardvalue = 10;
							break;

						case 'q': case 'Q':
							cardvalue = 10;
							break;

						case 'k': case 'K':
							cardvalue = 10;
							break;

						default:
							charidentifier = 1;

							break;

					}

					totalscore += cardvalue; //sums the score
					count += 1; //loop counter

				}
			else
			{
				outs << "wrong input" << endl; //tells user if there is a wrong input data
			}

			}

			while (count2 != acecounter) //if an ace is used it will add it
			{
				if (totalscore > win) //makes a decision for what value of ace to use

				{
					totalscore = totalscore - aceelleven + aceone;

				}

				count2 += 1;
			}
			if (charidentifier == 0) //if it isnt an incorrect card then it may proceed 
			{
				if (totalscore > win)
				{
					outs << "busted!" << endl; //going over 21 

				}
				else
				{
					outs << totalscore << endl;
					//output in result file

				}
			}
			else
			{
				outs <<"wrong input" << endl; //wrong input data by user
			}
		//reseting values 

			totalscore = 0;
			numbervalue= 0;
			charidentifier = 0;

			}
			else
			{
				outs <<"wrong input" << endl;
			}
		}

	}

	outs << "Finished!" << endl;
	cout << "Done!" << endl;

	getch(); // end of program

	ins.close();
	outs.close; //closing both files

}

i was able to compile it by just fixing the syntax errors

replace the period with a semicolon after endl

cout << "The Blackjack Program is starting" << endl.

this if statement is missing opening curly braces

if ( ((cardchar >= '2') && (cardchar <= '9')) || (cardchar == 'a', 'A', 't', 'T', 'j', 'J', 'q', 'Q', 'k', 'K') )
  		switch (cardchar)
 		{

remove the semicolon after the paranthesis:

while (loopend != -99); //when to end the loop	
{

close is a member function, so it needs to be called with parenthesis just like ins.close() was

outs.close; //closing both files

I think that was all I had to change. But I'm using a different compiler than you are so I'm not sure that will be everything.

If you find more try fixing them yourself. In case your unsure, the error messages you received actually provide useful feedback (in your case line numbers which are very helpful)

This article has been dead for over six months. Start a new discussion instead.