Adventure book

I would like to write a "Random" adventure book, with a little user input.
I will have to pass data to functions, which is not a biggie. I would like the program to loop for continued reading. I will have the user input new data for the next story. Not sure how I want to word the output, to get input yet.

I'm just asking for some ideas with approaching this, not how to write it.
I will however need some guidance with checking the random number. I don't want the same story to be replayed if the user chooses to use the program again.
(I would like to add more stories, but for now I will stick to 5.)

I have a rough concept written:

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
#include <iostream>
#include <ctime>
#include <cstdlib>

/* Story Functions */
int storyOne();
int storyTwo();
int storyThree();
int storyFour();
int storyFive();

int main()
{
srand( time( NULL ) );

std :: string name; //Main character name
int heros;          //Companions in story
int died;           //Companions or enemies died
int survivors;      //Suvivors
const int gold = 1200; //Some kind of reward

std :: cout << "Enter your name" << std :: endl;
/*Ask user if they wish to change name??*/
std :: cin >> name;

/*Loop this, for new unique story*/
std :: cout << "Enter a number" << std :: endl;
std :: cin >> heros;
std :: cout << std :: endl;
std :: cout << "Enter a number less than the first" << std :: endl;
std :: cin >> died;
std :: cout << std :: endl;

switch ( ( rand() % 5 + 1 ) ) //Random number to select 1 of 5 stories
{
case 1:
storyOne();
break;
case 2:
storyTwo();
break;
case 3:
storyThree();
break;
case 4:
storyFour();
break;
case 5:
storyFive();
break;
default:
break;
}

return 0;
}

int storyOne()
{
std :: cout << "Story 1" << std :: endl;
}
int storyTwo()
{
std :: cout << "Story 2" << std :: endl;
}
int storyThree()
{
std :: cout << "Story 3" << std :: endl;
}
int storyFour()
{
std :: cout << "Story 4" << std :: endl;
}
int storyFive()
{
std :: cout << "Story 5" << std :: endl;
}


Any and all comments will be more than welcomed! Thanks =)
Last edited on
I would say store your stories on separate text files or in a different file under a namespace such as Writtendata::story1(). This could help to separate the coding aspect and the writing aspect and improve organization.

for the loop, you would want to start out with something simple like
1
2
3
4
5
6
7
8
bool running = true
while(running)
{
      //code here
      //user is done, changes running to false

}
std::cout << thanks for playing!


for your random numbers, create a new integer each loop and assign it a random number, then switch that random number. If you wish for the stories not to repeat themselves, you could assign each story a Boolean value that is checked to false after being selected to take it out of the possible pool of choices.
Last edited on
Topic archived. No new replies allowed.