Program not building.

Hello,

I have been puzzling over this for some time now and unable to find a fix.
I bought the book Beginning C++ Through Game Programming, 3rd edition, Michael Dawson.

On page 17 it uses the code that I have included below this message. I have taking this code straight from the books website and pasted it into the compiler and it comes up with the following error.

1>c:\users\acer\documents\visual studio 2010\projects\game stats\game stats\game stats.cpp(19): error C2440: '=' : cannot convert from 'const char [2]' to 'char'

I am using the compiler that the book recommends, Microsoft Visual 2010 Express Edition.

I am guessing that there is nothing wrong with the code since it is the one that the book provides, so I am assuming that it has something to do with the way that the complier is set up.

Any light that could be shone onto this problem would be greatly appreciated since it's proved too much of a head scratcher for me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  // Game Stats
// Demonstrates declaring and initializing variables

#include <iostream>
using namespace std;

int main()
{
	int score;				
	double distance;		
	char playAgain;			
	bool shieldsUp;			

	short lives, aliensKilled;

	score = 0;
	distance = 1200.76;
	playAgain = 'y';
	shieldsUp = true;
	lives = 3;
	aliensKilled = 10;
		
	double engineTemp = 6572.89;

	cout << "\nscore: "		<< score << endl;
	cout << "distance: "	<< distance << endl;
	cout << "playAgain: "	<< playAgain << endl;
	//skipping shieldsUp since you don't generally print Boolean values
	cout << "lives: "		<< lives << endl;
	cout << "aliensKilled: "<< aliensKilled << endl;
	cout << "engineTemp: "	<< engineTemp << endl;

	int fuel;
	cout << "\nHow much fuel? ";
	cin >> fuel;
	cout << "fuel: " << fuel << endl;

	typedef unsigned short int ushort;
	ushort bonus = 10;
	cout << "\nbonus: " << bonus << endl;

	return 0;
}




Do you perhaps have "double quotes" around the 'y' on line 18 instead of 'single quotes' as the example does? That would easily cause the error you are getting.
closed account (iAk3T05o)
Initialize your variables.
1
2
3
char playagain = 'y'; //initialization
char playagain;
playagain = 'y' //assignment 
Thanks to you both for the quick reply. I am not sure what went wrong or why but it is working now. I downloaded the code off the web again and fed it into the compiler - this time it worked. I must have done something accidentally to create the error, no idea what exactly it was - but I'm up and running again, now on page 18 :)
Topic archived. No new replies allowed.