The Game i was making from a guide wont work

i was told in C++ Programming Secound Edition For The Absolute Begginer
as far as my beginner programming skills can tell it looks exactly the same but still it gives me 17 differnt errors! by the way i only started yesterday so is it common for beginners to get this many errors from basic code?

(58)error C2059: syntax error : '}'
(58)error C2143: syntax error : missing ';' before '}
(58)error C2059: syntax error : '}'
(57)error C2059: syntax error : 'return
(45)see declaration of 'cout'
(54)error C2086: 'int cout' : redefinition
(54) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
54) : error C2143: syntax error : missing ';' before '<<'
(45) : see declaration of 'cout'
(52) : error C2086: 'int cout' : redefinition
(52) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
(50) : error C2059: syntax error : '<<'
(45) : see declaration of 'cout'
(49) : error C2086: 'int cout' : redefinition
(49) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
(49) : error C2143: syntax error : missing ';' before '<<'
(45) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
(45) : error C2143: syntax error : missing ';' before '<<'
(42) : error C2059: syntax error : '<<'

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <string>

int main(void)
{
	using std::cout;
	using std::cin;
	using std::string;
	int buddies;
	int afterBattle;
	string exit;
	cout << "You Are a Pirate and are walking"
		<< " along in the crim filled \n"
		<< " city of Darkness (in 1789). "
		<< "How Many of your pirate buddies \n"
		<< "do you bring along? (Any number between 11 and 115)\n";

	cin >> buddies;
	afterBattle = 1 + buddies - 10; 

	cout << "Suddenly 10 Elite Musketeers jump out "
		<< " from the local tavern and \n"
		<< " draw their swords. "
		<< "10 musketeers and 10 pirates die in the \n"
		<< "battle. There are only "
		<< (buddies + 1 - 10)
		<< " pirates left, including you \n\n";
	
	cout << " the fallen drop a total of 107 gold coins.\n"
		<< " the bounty is split evenly, which works out to "
		<< (107 / afterBattle) << " gold coins \n"
		<< "for each survivor. \n";
	cout << "The Last " << (107 % afterBattle) << " are fought over "
		<< "in a big drunken brawl.\n";
	cout << "These last few coints are spent on more booze during the \n"
		<< "course of the brawl. Eventually everyone Retires\n"
		<< " peacefully on the bar room floor. \n"
		<< " another successful day as a pirate!\n";
	return  0;
}

<< (buddies + 1 - 10)
<< " pirates left, including you.\n\n";

cout << " the fallen drop a total of 107 gold coins.\n"
<< " the loot is split evenly witch works out to "
<< (107 / afterBattle) <<  " gold coins \n"
	<< " for each survivor leaving ";
cout << (107 % afterBattle) << " unclaimed.\n";
<< "How many of your pirate buddies \n"
<< " do you bring along? (Any number between 11 and 115)\n"; 
cout << "You and the others argue over who should get the extra \n"
<< " coins. and soon a big drunken brawl breaks out! \n\n";
cout << " In the end you are triumphant and "
<< (107 / afterBattle) + (107 % afterBattle)
<< " coins richer!\n\n";
return 0;
}
Last edited on
If you only started yesterday you've jumped in way over your head. You're going to want to backtrack a lot, and learn the language. You should actually know what every single line of text in there is for, and what it does.

int main(void) is usually just Int main ()

as far as I know....

also you need a ; at the line of just about every line of code. Can't tell you the exact reason, as I'm just learning as well.

ex.

cout << "You Are a Pirate and are walking"
<< " along in the crim filled \n"
<< " city of Darkness (in 1789). "
<< "How Many of your pirate buddies \n"
<< "do you bring along? (Any number between 11 and 115)\n";


should actually be

cout << "You Are a Pirate and are walking";
<< " along in the crim filled \n";
<< " city of Darkness (in 1789). ";
<< "How Many of your pirate buddies \n";
<< "do you bring along? (Any number between 11 and 115)\n";


You will learn a lot better if you start learning from the beginning. try a google search "learn C++"

as an expression I'd say, it's best to learn to swim in the shallow end, before trying to dive in the deepend.

lol this only page 20 of the book on the for brand new beginners section...
and i know cout means print screen cin means user input etc i know 89% of those lines
Last edited on
Dakrhunter if you have Skype or AIM message me your user name and I will help you walk through the code and discover your errors. The code is all crumpled up there, I can't read it well.
Last edited on
cout << "You Are a Pirate and are walking"
<< " along in the crim filled \n"
<< " city of Darkness (in 1789). "
<< "How Many of your pirate buddies \n"
<< "do you bring along? (Any number between 11 and 115)\n";


should actually be

cout << "You Are a Pirate and are walking";
<< " along in the crim filled \n";
<< " city of Darkness (in 1789). ";
<< "How Many of your pirate buddies \n";
<< "do you bring along? (Any number between 11 and 115)\n";

Actually the first option works and the second does not.

The problem is that about half your code is out of scope (the bottom half is outside of main)
ty for help warnis
its now only got 6 errors and the code i typed is exactly the same as it is in the book..


(49) : error C2143: syntax error : missing ';' before '<<'
(41) : error C2143: syntax error : missing ';' before '<<'
(16) : error C2143: syntax error : missing ';' before '<<'
(15) : error C2143: syntax error : missing ';' before '<<'
(14) : error C2143: syntax error : missing ';' before '<<'
(13) : error C2143: syntax error : missing ';' before '<<'

do you think i just payed for a rip of then? since that guide obviously isnt very good
1
2
<< (buddies + 1 - 10)
<< " pirates left, including you.\n\n";

Should be:
1
2
cout << (buddies + 1 - 10)
<< " pirates left, including you.\n\n";

It's on line 42 of your first posted code, you didn't put cout before the <<. Atleast I don't think so, which could be causing the rest of the statements to go whack.
NVM using your advice i fixed it ty mbittel12
Last edited on
Can you repost the modified code so we can see what you've changed?
Looks like you typed it in wrong.
The second part looks like it belongs to the next exercise.

The second part starts after line 40. So just delete/comment out all the code after that and it should be fine.
It's just simple syntax errors, I corrected them for you. There was one or two semi-colons out of place, here's the working result:

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
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <string>

int main(void)
{
	using std::cout;
	using std::cin;
	using std::string;
	int buddies;
	int afterBattle;
	string exit;
	cout << "You Are a Pirate and are walking"
		<< " along in the crim filled \n"
		<< " city of Darkness (in 1789). "
		<< "How Many of your pirate buddies \n"
		<< "do you bring along? (Any number between 11 and 115)\n";

	cin >> buddies;
	afterBattle = 1 + buddies - 10; 

	cout << "Suddenly 10 Elite Musketeers jump out "
		<< " from the local tavern and \n"
		<< " draw their swords. "
		<< "10 musketeers and 10 pirates die in the \n"
		<< "battle. There are only "
		<< (buddies + 1 - 10)
		<< " pirates left, including you \n\n";
	
	cout << " the fallen drop a total of 107 gold coins.\n"
		<< " the bounty is split evenly, which works out to "
		<< (107 / afterBattle) << " gold coins \n"
		<< "for each survivor. \n";
	cout << "The Last " << (107 % afterBattle) << " are fought over "
		<< "in a big drunken brawl.\n";
	cout << "These last few coints are spent on more booze during the \n"
		<< "course of the brawl. Eventually everyone Retires\n"
		<< " peacefully on the bar room floor. \n"
		<< " another successful day as a pirate!\n";
	cout << (buddies + 1 - 10)
		<< " pirates left, including you.\n\n";

	cout << " the fallen drop a total of 107 gold coins.\n"
		<< " the loot is split evenly witch works out to "
		<< (107 / afterBattle) <<  " gold coins \n"
		<< " for each survivor leaving ";
	cout << (107 % afterBattle) << " unclaimed.\n"
		<< "How many of your pirate buddies \n"
		<< " do you bring along? (Any number between 11 and 115)\n"; 
	cout << "You and the others argue over who should get the extra \n"
		<< " coins. and soon a big drunken brawl breaks out! \n\n";
	cout << " In the end you are triumphant and "
		<< (107 / afterBattle) + (107 % afterBattle)
		<< " coins richer!\n\n";

        return 0;
}


With code written this way it is easy to get confused, try to leave a space between each cout << statement so you can search through it easier for syntax errors.
Last edited on
but do you think i got ripped of since its the same as it is in the book ive just had a friend check and i never typed anything differnt from the book
Last edited on
Possibly, or if it is exactly like the book then maybe it's giving you a messed up program to try to fix the problems, like a test of some sort. Not sure though...do you have AIM, I can send you a PDF book that saved my LIFE in programming haha
What book is it mbittel12?
Topic archived. No new replies allowed.