Error C2061: Identifier 'cout'

need to fix this error

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 4414 Views - Last Post: 15 January 2009 - 06:05 AM Rate Topic: -----

#1 ArmageddonAsh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 14-January 09

Error C2061: Identifier 'cout'

Post icon  Posted 14 January 2009 - 08:13 AM

im doing a project as part of my course in which i have to make BlackJack program but im having serious trouble - it worked perfect one day and the next kept getting 11 errors, 10 of which i have now fixed but this is:

Error C2061: syntax error : identifer 'cout'

has proved impossible to fix, any ideas i have tried everything i could think of, from copying the code to a new project and i have gone over the code and as far as im aware it should work fine.

the error occurs on line 74, but if i remove that cout it just goes down to the next one

heres my code:

 

#include "stdafx.h";
#include <iostream>
using namespace std;
 int CheckAce;

void check_value(char card, int& actual_value)
{   // this code is used to enter the value of the card the user has
	// depending on what the user enters for the value
	switch(card)
	{
	case '1':
		actual_value = 1;
		break;
	case '2':
		actual_value = 2;
		break;
	case '3':
		actual_value = 3;
		break;
	case '4':
		actual_value = 4;
		break;
	case '5':
		actual_value = 5;
		break;
	case '6':
		actual_value = 6;
		break;
	case '7':
		actual_value = 7;
		break;
	case '8':
		actual_value = 8;
		break;
	case '9':
		actual_value = 9;
		break;
	case 'T':
		actual_value = 10;
		break;
	case 'A':
		actual_value = 11;
		CheckAce = CheckAce + 1;
		break;
	case 'J':
		actual_value = 10;
		break;
	case 'K':
		actual_value = 10;
		break;
	case 'Q':
		actual_value = 10;
		break;
	}
}


int _tmain(int argc, _TCHAR* argv[])
{
	char card[5], PlayAgain;
   
	int actual_value[5], cardno(0), Total(0); 
	
	// the do while is used to allow the user to play the game again if they enter Y or y
	do{

}
	// this code is used to introduce the game and explain what they need
	//to do if they get a Jack, King, Queen or Ace
	// it also is used to ask how many cards they have
	//then it asks the user to enter the value for each card
	cout << "Welcome To BlackJack";
	cout << "\nWhen Entering Choice Please Enter:";
	cout << "\nT For 10, K for King, J for Jack, Q For Queen And A Ace";
	cout << "\nNow Please Enter number of cards: ";
	cin >> cardno;
	cout << endl << "Can You Please Enter Each Card Value: ";

	for (int i(0); i < cardno; i++)
	{
		cin >> card[i];
		card[i] = toupper(card[i]);
		check_value(card[i], actual_value[i]);
		Total = Total + actual_value[i];
	}
	// this part checks how many Aces the user has and if the total is over 21 and if it is then
	// the correct number of points is taken off so that the user doesnt go bust
	if ((CheckAce == 1) && (Total > 21))
	Total = Total - 10;
	else if ((CheckAce == 2 ) && (Total > 21))
	Total = Total - 10;
	else if ((CheckAce == 3) && (Total > 21))
	Total = Total - 9;
	else if ((CheckAce == 4) && (Total > 21))
	Total = Total - 8;
	else if ((CheckAce == 5) && (Total > 21))
	Total = Total - 7;
	else 
	
	Total = Total;
	// if the user has 21 or under this code is run
	if (Total <=21)
	cout << "The total is " << Total; 
	cout << "Well Done You Have Won!!!";
	// if the user as over 21 this code is run
	if (Total >=21)
	cout << "The total is " << Total; 
	cout << "Sorry You Have Gone Bust";
 
	   while (PlayAgain=='y'||PlayAgain=='Y');
	 cout << "\nThanks for playing";
 
	return 0;
}




any help would be very greatful

This post has been edited by ArmageddonAsh: 14 January 2009 - 08:20 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Error C2061: Identifier 'cout'

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: Error C2061: Identifier 'cout'

Posted 14 January 2009 - 08:16 AM

Use the other slash for code tags. At a quick glance you're missing a while to pair with the do and that missing statement/semicolon could be throwing the compiler off by one line and thus its telling you that cout is unidentified. Try:

do{

} while(condition);
cout << ...



edit: I see that you have a while but the brackets for do don't enclose any of what you have in there, move that bottom bracket down to the left side of while.

This post has been edited by KYA: 14 January 2009 - 08:17 AM

Was This Post Helpful? 0
  • +
  • -

#3 ArmageddonAsh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 14-January 09

Re: Error C2061: Identifier 'cout'

Posted 14 January 2009 - 08:19 AM

wow fast reply, thanx
will fix the post

but i have the While at the bottom of the code

while (PlayAgain=='y'||PlayAgain=='Y');

could it be the code i have under it, maybe change that to an if statement or something, as i want:

cout << "\nThanks for playing";

to appear if the uer enters N or n and exits the game
Was This Post Helpful? 0
  • +
  • -

#4 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: Error C2061: Identifier 'cout'

Posted 14 January 2009 - 08:21 AM

You have

do
{
}//this is the end of the do, while isn't here

code in the middle isn't being looped and you have a syntax error above

//while is way down here


Was This Post Helpful? 0
  • +
  • -

#5 ArmageddonAsh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 14-January 09

Re: Error C2061: Identifier 'cout'

Posted 14 January 2009 - 08:24 AM

okay thanx, i removed that and got a new error, a fatal one
end of file found before the left brace

should i move the "{" down, where?
Was This Post Helpful? 0
  • +
  • -

#6 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: Error C2061: Identifier 'cout'

Posted 14 January 2009 - 08:27 AM

Do this:


#include <iostream>
using namespace std;
 int CheckAce;

void check_value(char card, int& actual_value)
{   // this code is used to enter the value of the card the user has
	// depending on what the user enters for the value
	switch(card)
	{
	case '1':
		actual_value = 1;
		break;
	case '2':
		actual_value = 2;
		break;
	case '3':
		actual_value = 3;
		break;
	case '4':
		actual_value = 4;
		break;
	case '5':
		actual_value = 5;
		break;
	case '6':
		actual_value = 6;
		break;
	case '7':
		actual_value = 7;
		break;
	case '8':
		actual_value = 8;
		break;
	case '9':
		actual_value = 9;
		break;
	case 'T':
		actual_value = 10;
		break;
	case 'A':
		actual_value = 11;
		CheckAce = CheckAce + 1;
		break;
	case 'J':
		actual_value = 10;
		break;
	case 'K':
		actual_value = 10;
		break;
	case 'Q':
		actual_value = 10;
		break;
	}
}


int main()
{
	char card[5], PlayAgain;
   
	int actual_value[5], cardno(0), Total(0);
   
	// the do while is used to allow the user to play the game again if they enter Y or y
	do{


	// this code is used to introduce the game and explain what they need
	//to do if they get a Jack, King, Queen or Ace
	// it also is used to ask how many cards they have
	//then it asks the user to enter the value for each card
	cout << "Welcome To BlackJack";
	cout << "\nWhen Entering Choice Please Enter:";
	cout << "\nT For 10, K for King, J for Jack, Q For Queen And A Ace";
	cout << "\nNow Please Enter number of cards: ";
	cin >> cardno;
	cout << endl << "Can You Please Enter Each Card Value: ";

	for (int i(0); i < cardno; i++)
	{
		cin >> card[i];
		card[i] = toupper(card[i]);
		check_value(card[i], actual_value[i]);
		Total = Total + actual_value[i];
	}
	// this part checks how many Aces the user has and if the total is over 21 and if it is then
	// the correct number of points is taken off so that the user doesnt go bust
	if ((CheckAce == 1) && (Total > 21))
	Total = Total - 10;
	else if ((CheckAce == 2 ) && (Total > 21))
	Total = Total - 10;
	else if ((CheckAce == 3) && (Total > 21))
	Total = Total - 9;
	else if ((CheckAce == 4) && (Total > 21))
	Total = Total - 8;
	else if ((CheckAce == 5) && (Total > 21))
	Total = Total - 7;
	else
   
	Total = Total;
	// if the user has 21 or under this code is run
	if (Total <=21)
	cout << "The total is " << Total;
	cout << "Well Done You Have Won!!!";
	// if the user as over 21 this code is run
	if (Total >=21)
	cout << "The total is " << Total;
	cout << "Sorry You Have Gone Bust";
 
	   }while (PlayAgain=='y'||PlayAgain=='Y');
	 cout << "\nThanks for playing";
 
	return 0;
}




You weren't using the command line arguments so I just got rid of them.
Was This Post Helpful? 0
  • +
  • -

#7 ArmageddonAsh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 14-January 09

Re: Error C2061: Identifier 'cout'

Posted 14 January 2009 - 08:30 AM

thanx but now im getting a Fatal Error C1010: Unexpected end of file while looking for precomplied header
Was This Post Helpful? 0
  • +
  • -

#8 .Maleficus.  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 129
  • Joined: 07-March 08

Re: Error C2061: Identifier 'cout'

Posted 14 January 2009 - 09:23 AM

None of your If's have any braces. Fix that and try it again :).
Was This Post Helpful? 0
  • +
  • -

#9 ArmageddonAsh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 14-January 09

Re: Error C2061: Identifier 'cout'

Posted 14 January 2009 - 09:37 AM

im sorry but i dont understand what you mean, as far as im aware they do have the "(" or ")" at the beginning or the end of them,
Was This Post Helpful? 0
  • +
  • -

#10 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: Error C2061: Identifier 'cout'

Posted 14 January 2009 - 10:59 AM

Currently:

 if (Total >=21)
	cout << "The total is " << Total;
	cout << "Sorry You Have Gone Bust";
//no braces!!



Should be:

 if (Total >=21)
{
	cout << "The total is " << Total;
	cout << "Sorry You Have Gone Bust";
}//etc



I don't see how you're getting an error though. I compiled the example code I had above fine. Check all of your brace pairs.
Was This Post Helpful? 0
  • +
  • -

#11 ArmageddonAsh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 14-January 09

Re: Error C2061: Identifier 'cout'

Posted 14 January 2009 - 11:08 AM

i remember something about having to copy some files to some place to get something to work, could that be it?

if if you ran the code fine then thats all i can think of
Was This Post Helpful? 0
  • +
  • -

#12 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: Error C2061: Identifier 'cout'

Posted 14 January 2009 - 11:10 AM

Maybe, why do you have a stdafx.h anyway? Its probably not the problem though. Run my earlier code post and see if it will compile.
Was This Post Helpful? 0
  • +
  • -

#13 ArmageddonAsh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 14-January 09

Re: Error C2061: Identifier 'cout'

Posted 14 January 2009 - 11:14 AM

i cant at the moment as im on my laptop (vista 64) and i need the code to be used on a XP 32 bit system at Uni, i will try it tomorrow

thanx

any other ideas what it could be?

i tried to send you a PM, but it wouldnt let me any ideas?

This post has been edited by ArmageddonAsh: 14 January 2009 - 11:15 AM

Was This Post Helpful? 0
  • +
  • -

#14 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Error C2061: Identifier 'cout'

Posted 14 January 2009 - 11:19 AM

You have to have 10 or more posts around the forums to send/receive PMs. This prevents the spamming of PMs.

:)
Was This Post Helpful? 0
  • +
  • -

#15 ArmageddonAsh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 14-January 09

Re: Error C2061: Identifier 'cout'

Posted 14 January 2009 - 11:20 AM

okay thanx for the info, i guess i will have to wait
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2