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;
}
|