Need help with expression error.

Pages: 12
closed account (48T7M4Gy)
Also, you can't call main() in your program as you have done in line 92
closed account (48T7M4Gy)
I took the liberty of making a few changes. Clearer names for variables and functions and got rid of some rubbish in terms of repeating game calls and descriptions . Feel free to use or not - mine works so you might find it useful for comparison :)

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
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <string>

using namespace std;

int setup_party_size()
{
    int random_no_members = 0;
    char dice_roll;
    
    cout << "Welcome to Professor Scott and the Temple of Doom!\n";
    cout << "Before you can enter you must roll a dice to see how many of your friends will follow you!\n\n";
    
    cout << "Please [R]oll the dice to decide how many will dare enter with you.\n";
    
    cin >> dice_roll;
    
    if (dice_roll == 'R') {
        srand(time(NULL));
        random_no_members = rand() % 6 + 1;
        cout << "You have been joined by " << random_no_members << " of your friends!\n\n";
    }
    else {
        cout << "\nYou can't not roll!\n";
    }
    
    return random_no_members;
}

void fill_in_names(int no_members, string *member_list)
{
    for (int i = 0; i < no_members; i++) {
        cout << "Please enter a name for your party member: ";
        cin >> member_list[i];
    }
    
    cout << "Your party consists of: ";
    cout << endl;
    
    for (int x = 0; x < no_members; x++) {
        cout << member_list[x] << " " << x << "\n";
    }
}

void game()
{
    int no_members = setup_party_size();
    string* member_name_list = new string[no_members];
    
    fill_in_names(no_members, member_name_list);
    
    cout << "Here's a repeat of the list of names:\n";
    for (int y = 0; y < no_members; y++) {
        cout << member_name_list[y] << "\n";
    }
    cout << "That's the end of the list\n";
}

int main()
{
    char menu_choice;
    cout << "Main Menu:\n";
    cout << "[S]tart Game\n";
    cout << "[E]xit Game\n\n";
    
    cout << "Please choose an option: ";
    cin >> menu_choice;
    
    if (menu_choice == 'S') {
        cout << "\nWelcome to The Temple of Doom!";
        game();
    }
    else if (menu_choice == 'E') {
        cout << "\nMaybe you'll enter next time.";
    } else {
        cout << "\nPlease enter a valid option\n";
    }
    return 0;
}


Main Menu:
[S]tart Game
[E]xit Game

Please choose an option: S

Welcome to The Temple of Doom!Welcome to Professor Scott and the Temple of Doom!
Before you can enter you must roll a dice to see how many of your friends will follow you!

Please [R]oll the dice to decide how many will dare enter with you.
R
You have been joined by 4 of your friends!

Please enter a name for your party member: aa
Please enter a name for your party member: ss
Please enter a name for your party member: dd
Please enter a name for your party member: ff
Your party consists of: 
aa 0
ss 1
dd 2
ff 3
Here's a repeat of the list of names:
aa
ss
dd
ff
That's the end of the list
Program ended with exit code: 0
Topic archived. No new replies allowed.
Pages: 12