bloodshed c++ code problems
So I got Beginning C++ Game Programming, off of amazon. I'm starting too read it, an work on some of the examples. But I can't figure out what's wrong with it. I tried an earlier example, but I couldn't find answer too that one either. I looked at the included code, and it looked pretty much the same. Anyway, here's the example. I would like to know what I have to fix too make this code run.
// 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 shieldUp since you don't generally print Boolean values
cout << "lives: " << lives << endl;
cout << "alienKilled: "<< 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;
}
What you have to fix is, you haven't told us what error the compiler gives you, so we have no way to help you.
distance = 1200.76; // you need a semicolon here
cout << "\nscore: " << score << endl; // you need a semicolon here
cout << "\nbonus: " << bonus << endl; // you need a semicolon here
three semicolon issues, enjoy!
cout << "\nscore: " << score << endl; // you need a semicolon here
cout << "\nbonus: " << bonus << endl; // you need a semicolon here
three semicolon issues, enjoy!
On this line,
cout << "\nbonus: " << bonus << endl:
change to
cout << "\nbonus: " << bonus << endl;
Semi-colons can be a pain.
cout << "\nbonus: " << bonus << endl:
change to
cout << "\nbonus: " << bonus << endl;
Semi-colons can be a pain.
thanks for replying, that fixed the problem but now I have a new problem.
// Game Stats 2.0
// Demonstrates arithmetic operations with variables
#include <iostream>
using namespace std;
int main()
{
unsigned int score = 5000;
cout << "score: " << score << endl;
//altering the value of a variable
score = score + 100
cout << "score: " << score << endl;
//combined assignment operator
score += 100;
cout << "score: " << score << endl;
//increment operators
int lives = 3;
cout << "lives: " << lives << endl;
lives = 3
lives++;
cout << "lives: " << lives << endl;
lives = 3;
int bonus = ++lives * 10;
cout<< "lives, bonus = " << lives << ", " << bonus << endl;
//integer wrap around
score = 4294967295;
cout << "\nscore: " << score << endl;
++score;
cout << "score: " << score << endl;
return 0;
}
/ line 14 parse
/ line 25 parse
/ line 33 (warning parse)
[Edited by - Agreenknight on October 21, 2005 5:59:53 PM]
// Game Stats 2.0
// Demonstrates arithmetic operations with variables
#include <iostream>
using namespace std;
int main()
{
unsigned int score = 5000;
cout << "score: " << score << endl;
//altering the value of a variable
score = score + 100
cout << "score: " << score << endl;
//combined assignment operator
score += 100;
cout << "score: " << score << endl;
//increment operators
int lives = 3;
cout << "lives: " << lives << endl;
lives = 3
lives++;
cout << "lives: " << lives << endl;
lives = 3;
int bonus = ++lives * 10;
cout<< "lives, bonus = " << lives << ", " << bonus << endl;
//integer wrap around
score = 4294967295;
cout << "\nscore: " << score << endl;
++score;
cout << "score: " << score << endl;
return 0;
}
/ line 14 parse
/ line 25 parse
/ line 33 (warning parse)
[Edited by - Agreenknight on October 21, 2005 5:59:53 PM]
Giving the actual compiler errors would be more helpful.
These look like fairly elementary mistakes (missing semi colons and such). Maybe instead of posting here with these kind of compiler errors you should be spending more time trying to solve the problem yourself? Thats the only way you'll learn and improve yourself as a programmer.
Missing semi colons arent exactly gonna take you weeks to find. I found both of them within about 10 seconds (looking at those line numbers might help!)
These look like fairly elementary mistakes (missing semi colons and such). Maybe instead of posting here with these kind of compiler errors you should be spending more time trying to solve the problem yourself? Thats the only way you'll learn and improve yourself as a programmer.
Missing semi colons arent exactly gonna take you weeks to find. I found both of them within about 10 seconds (looking at those line numbers might help!)
I'm sorry for not posting the code in a format you like. I looked on the forum faq, http://www.gamedev.net/community/forums/showfaq.asp?forum_id=11, didn't find where it says how to post code. I'm just not getting these parse errors. I looked at the code, found I missed part of it, and got more another error. So maybe it's not a big deal, but it's a big deal to me. Next time, I'll post in the beginning section.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement