help with simple code

Hey i just got a book called "beginning C++ through game programming" i am trying to follow trough the book and write out all of the examples to get the most out of it. anyways i havent had any trouble with any up untill this one and i have scouted for typo's or anything obvious that i may have messed up on. im using visual c++ express 2010 windows 7. and this is the code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;

int main()
{
	
	const int ALIEN_POINTS = 150;
	int aliensKilled = 10;
	int score = aliensKilled * ALIEN_POINTS;
	cout << "score:" << score<< endl;

	enum difficulty {NOVICE, EASY, NORMAL, HARD, UBEATABLE};
	difficulty myDifficulty = EASY;
	
	
	enum shipCost {FIGHTER_COST, BOMBER_COST, CRUISER_COST = 50};
	shipCost myShipCost = BOMBER_COST;

	cout << "\nTo upgrade my ship to a cruiser will cost"
		<< (CRUISER_COST - myShipCost) <<" Resource Points.\n";

		return 0;

		}
all its supposed to do is give me a window with a score of 1500 ( 10 * ALIENS_KILLED) and tell me how may points to upgrade my ship to a "cruiser" which should be 24 CRUISER_COST - myShipCost or BOMBER_COST)

like i said i am verry new to this, this is chapter one of a book i started reading on a topic i know nothing about, so sorry if this is a noob question or if its something stupid that im missing, but any help would be great
I have not understood what is the question?! If you get a compile error then please report its text.
You haven't given the bomber a value. If you give that a value it should be right. Other than that it will minus by one more than likely meaning the ship cost will be 49 instead of what you want.
1
2
enum shipCost {FIGHTER_COST, BOMBER_COST=26, CRUISER_COST = 50};
	shipCost myShipCost = BOMBER_COST;

Hope that is it :)
Here is the output it produces:

score:1500

To upgrade my ship to a cruiser will cost49 Resource Points.


If you don't see this when you run it, I suspect you need to read this:
http://www.cplusplus.com/forum/beginner/1988/
and please do NOT use system("pause");

You will definitely benefit from this:
http://www.cplusplus.com/forum/articles/1295/
as your question is just too vague for us to know for sure what your problem actually is.
Last edited on
when i ran this it worked fine my output is
score:1500

To upgrade my ship to a cruiser will cost49 Resource Points.

remember to add \n in your last cout statement so the output will be
To upgrade my ship to a cruiser will cost
49 Resource Points.

i an not sure what the problem is and it would be nice if you could elaborate more on the issue you have.
by the way, great variable naming, makes it really easy to read :).
are you just starting out or do u know all the functions/statements used in this program?
sorry i am getting a complier error

1
2
3
1
1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup
1>C:\Users\russ\Documents\C++\gaming\game_stats_3.0\Debug\game_stats_3.0.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


this was complier error from firrs thread, and i still get error when i change the value. i re wrote that whole line so it looks like
1
2
enum shipCost {FIGHTER_COST = 25, BOMBER_COST = 26, CRUISER_COST = 50};
	shipCost myShipCost = BOMBER_COST;


now compile and get error that looks like
1
2
3
1
1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup
1>C:\Users\russ\Documents\C++\gaming\game_stats_3.0\Debug\game_stats_3.0.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


sorry so much stuff in the code brackets im not sure why im not getting this to compile correctly and not sure what you guys need to help me.

its not a matter of it opening and closing quickly, its a compiler error, i have used system("pause"); on other ones but this is also just begginer stuff im doing just to get the hang of it. my book says to run it from a batch file that i tried but that did not work either when the window closes immediatly.
Last edited on
Are you sure you created a console app? Make sure of that...
i thought i did... hmm ok well that solved the issue i must have opened something wrong when creating new project. im sorry for all of the trouble everyone but thank you for all of your help


Topic archived. No new replies allowed.