• Advertisement
Sign in to follow this  

bloodshed c++ code problems

This topic is 4506 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
On this line,

cout << "\nbonus: " << bonus << endl:

change to

cout << "\nbonus: " << bonus << endl;

Semi-colons can be a pain.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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!)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Read the forum FAQ too on how to post code properly.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement