Just started learning C++ by myself and need a little help :P

Hello Folks ! I just started learning the c++ language a few days ago, and I wanted to make a little ''You are the Hero'' story to practice and learn stuff. But now, I have trouble when I ask the ''reader'' for input : like when he has to make a decision and the texts he will receive will change depending on that input. I tried using the ''if'' statement with some int A,B,C, etc but it didn't work as expected. I also tried with switch, and this is where im asking for some advices from you guys !

Like I said, I just started a few ago, so don't be too mean about my skills :P

Thanks for reading and helping !

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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
 // Histoire Test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include "Histoire Test.h"

using namespace std;



void event1()
{
	int answer2;

	cout << "1. Yes \n\n2. I don't think I've ever heard this name before \n\n3. Maybe.. Maybe not.. (Asshole)";
	cin >> answer2;
}


void intro()
{

	int answer1;

	cout << "You follow the man, even though you don't think it's a good idea.. \n\n A few minutes of walk in, he asks you :\n" << endl;
	cout << "(Barnaby) -So, where are you from young man? And what brings you here, \nin this dank forest?\n" << endl;
	cout << "1. Im from the north, I was raised by the Wolvesmen of Klooklookx. Im here to avenge my people's death.\n\n";
	cout << "2. I came from the south. I am a bounty hunter, looking for treasures and epic quests.\n\n";
	cout << "3. I came from the caravel across the Windy Ocean, West of here. I am here to do buisness.\n\n";
	cout << "4. Say nothing.\n\n";
	cin >> answer1;

	
	switch (answer1)
	{
		{
		case1: cout << "(Barnaby) -Oh, so you're from the north... Well, let's try not to kill each other while we're still on the way, we have a long way to go before reaching town";
			break;
		}

		if (answer1 == 2)
		{
			cout << "I see.. Well if you try to rob me while im sleeping, I will cut your throat little man. Alright, let's get going.";
		}

		if (answer1 == 3)
		{
			cout << "From the West hmm? Do you happen to know a certain Shshshhshhsh ?";
			event1;
		}


		if (answer1 == 4)
		{
			cout << "Ugh.. Ok just follow me then..";
		}

		if (answer1 != 1, 2, 3, 4)
		{
			cout << "(Please enter a valid number)";
		}

	}
}




	int main()
{
		

		string name;
		cout << "\n\tEnter your name.";
		getline(cin, name);
		cout << "(" << name << ")"" -I am " << name << ".... Where are we?\n" << endl;

		if (name == "Johanna Jones")
		{
			cout << "(Barnaby) -What the heck?!? Johanna Jones ?! For real?! ..... No time to explain, come with me now! " << endl;
		}

		else
		{
			cout << "(Barnaby) -No time to explain, come with me now! \n ------------------------------------------------------------------" << endl;
		}

		intro();

		

		return 0;
}

Heya! Looks like a fun time, here's a snippet to get you started:

1
2
3
4
5
6
7
8
if (answer1 == 1){
      cout << "(Barnaby) -Oh, so you're from the north... Well, let's try not to kill each other"
           << "while we're still on the way, we have a long way to go before reaching town";
}
else if(answer1 == 2) {
      cout << "I see.. Well if you try to rob me while im sleeping, I will cut your throat little"
           << " man. Alright, let's get going.";
}


Make sure you change event1; to event1(); at some point as well.
Last edited on
Yeahhhh ! It fixed the problem ! Now, as a good learning coder, I've got into another problem 5mins after fixing this one.I wanted to have a sex selector a the start (Are you a boy or girl), but im not sure how to make this.

Do I make :

----------------------------

char sex;

cout << "Are you a boy or a girl ?" << endl;
cin >> sex;

cout << "My name is" name "and i'm a " sex " << endl;

----------------------------

I think i'm just missing the difference between int, void, char, string (this one i seem to be quite good with) class and others.

Again, thanks for the help !
For the gender selector, it'll be better if you create a while loop to accept only the words you want (in other words, loop the question if the person enters any other words beside "boy" or "girl")
Topic archived. No new replies allowed.