First game/program , having some trouble. Any help?

This is my first game/program, the drinking game. The problem I'm having is the 'drinks' function isn't displaying any text, it always just displays 1. Why/how would it even display a number? Also, for my drinks function, is it better to use a switch like I am or put the choices into an array of strings and choose from there?

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
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <windows.h>
#define CHOICES 7
#define TIME 10

void drinks();
int rand0toN(int n);

using namespace std;

int main(){

    int p;
    srand(time(NULL));  // Set seed for Randomizing

    //Prompt user with instructions and ask for players
    cout << "~~~~~Welcome to the drinking game!!~~~~~\n\n";
    cout << "Instructions:\n";
    cout << "1: Enter number of players and assign each player a number.\n";
    cout << "2: Each player has 10 seconds to complete drinking task. Start when\n";
    cout << "it says go.\n";
    cout << "3: If can/glass is not on the table before time is up\n";
    cout << "players loses and is out of the game.\n\n";
    cout << "Enter number of players(0 to exit): ";
    cin >> p;

    //Cycle through number of players, 0 to exit.
    while(p!=0){
            for(int i=1;i<=p;i++){
            cout << "Player " << i << endl;
            cout << drinks << " Ready... Set...\n";
                Sleep(6000);//Give them some time to read the challenge.
                cout << "GOOOOO!\n";
                //Count down timer.
                for(int s=1;s<=TIME;s++){
                    Sleep(1000);
                    cout << s << endl;
                }
            cout << "Time's up!!!\n\n";
            Sleep(1000);
            }
            cout << "Enter new number of players.(0 to exit)";
            cin >> p;
    }





system("pause");
return 0;
}

//This function makes a random choice for the player.
void drinks(){
    int c = rand0toN(CHOICES);
    switch(c){
        case 1:
            cout << "Take 1 gulps!";
            break;

        case 2:
            cout << "Take 2 gulps!";
            break;

        case 3:
            cout << "Take 3 gulps, or 1 shot!";
            break;

        case 4:
            cout << "Slam your drink! Go, go, go!";
            break;

        case 5:
            cout << "Choose someone for 2 gulps! Pick quick!";
            break;

        case 6:
            cout << "Choose someone for 3 gulps or 1 shot! Pick quick!";
            break;

        case 7:
            cout << "Take shots until the clock runs out!(Or slam your drink) Go, fast!";
            break;
    }


}
//Random number selection for function "drinks"
int rand0toN(int n){
    return (rand()%n)+1;

}


Last edited on
I'm not sure if this is your problem but you are not calling the drinks function here.

cout << drinks << " Ready... Set...\n";

why not do something like

1
2
3
4
drinks();
cout << "Ready, set..." << endl;
SLEEP(6000);
cout << "Go!";



Also your switch case doesn't have a default argument, why?
Also your switch case doesn't have a default argument, why?


That's simple, I forgot. It's my first program, so I'm bound to forget some things. But of course I overlook simple things like "()" on the end of my function. Thanks for your help!

Here is the completed version. Any ways to make it more efficent?

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
98
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <windows.h>
#define CHOICES 7
#define TIME 10

void drinks();
int rand0toN(int n);

using namespace std;

int main(){

    int p;
    srand(time(NULL));  // Set seed for Randomizing

    //Prompt user with instructions and ask for players
    cout << "~~~~~Welcome to the drinking game!!~~~~~\n\n";
    cout << "Instructions:\n";
    cout << "1: Enter number of players and assign each player a number.\n";
    cout << "2: Each player has 10 seconds to complete drinking task. Start when\n";
    cout << "it says go.\n";
    cout << "3: If can/glass is not on the table before time is up\n";
    cout << "players loses and is out of the game.\n\n";
    cout << "Enter number of players(0 to exit): ";
    cin >> p;

    //Cycle through number of players, 0 to exit.
    while(p!=0){
            for(int i=1;i<=p;i++){
            cout << "Player " << i << endl;
            drinks();
            cout << " Ready... Set...\n";
                Sleep(6000);//Give them some time to read the challenge.
                cout << "GOOOOO!\n";
                //Count down timer.
                for(int s=1;s<=TIME;s++){
                    Sleep(1000);
                    cout << s << endl;
                }
            cout << "Time's up!!!\n\n";
            Sleep(1000);
            }
            cout << "Enter new number of players.(0 to exit)";
            cin >> p;
    }





system("pause");
return 0;
}

//This function makes a random choice for the player.
void drinks(){
    int c = rand0toN(CHOICES);
    switch(c){
        case 1:
            cout << "Take 1 gulps!";
            break;

        case 2:
            cout << "Take 2 gulps!";
            break;

        case 3:
            cout << "Take 3 gulps, or 1 shot!";
            break;

        case 4:
            cout << "Slam your drink! Go, go, go!";
            break;

        case 5:
            cout << "Choose someone for 2 gulps! Pick quick!";
            break;

        case 6:
            cout << "Choose someone for 3 gulps or 1 shot! Pick quick!";
            break;

        case 7:
            cout << "Take shots until the clock runs out!(Or slam your drink) Go, fast!";
            break;
        default:
            break;
    }


}
//Random number selection for function "drinks"
int rand0toN(int n){
    return (rand()%n)+1;

}
Last edited on
Right on, I'm new to C++ programming as well, I wasn't sure if there was something going on that I wasn't aware of haha, like some special use of switch. Good luck!

edit: first program? pretty ambitious if you ask me! way to go.

edit #2:

1
2
3
4
5
6
        case 7:
            cout << "Take shots until the clock runs out!(Or slam your drink) Go, fast!";
            break;
        default:
            break;
    }


make case 7 the default case and it looks great to me! Also are you actually using the windows.h header file? I'm not to knowledgeable when it comes to c++ but I thought that was more for GUI kind of programming.
Last edited on
Well I decided I would teach myself programming about a week ago. I was going to start with Java, but I like C++ better. I'm about finished reading C++ without fear so I thought I would go ahead and start writing some programs. This is the best I could come up with to start. I am ambitious, I love programming! (That's a nerd statement if ever heard one.) Anyway, thanks for your help again.
Topic archived. No new replies allowed.