Nothing happens when I run program?

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

using namespace std;

int main()
{
{
    srand(time(0));
    int x = 1+(rand()%5);
    switch(x) {
    case 1:
    cout << "Hello!" << endl;
    break;
    case 2: {
    cout << "What's your name?" << endl;
    string y;
    cin >> y;
    cout << y << " is a stupid name!" << endl;
    }
    break;
    case 3:
    cout << "You're a loser" << endl;
    break;
    case 4:
    cout << "I like pie" << endl;
    break;
    case 5:
    cout << "I like so muche MORE pie then you can imagine" << endl;
    break;
    default:
    cout << ".....";
    }
    }
}

thanks in advance
OKay, I fixed that now, and I added a cin.get(); to the end, and put everything in a while loop, but now it's still just looping even though I have the cin.get();
What do you want the output to look like? Do you want it to loop randomly through the cases?
I want it to say one of the things randomly every time I press enter, if thats what you mean.
Can we see the new code?
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
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <cmath>

using namespace std;

int main()
{
{
    while (true) {
    srand(time(0));
    int x = 1+(rand()%5);
    switch(x) {
    case 1:
    cout << "Hello!" << endl;
    break;
    case 2: {
    cout << "What's your name?" << endl;
    string y;
    cin >> y;
    cout << y << " is a stupid name!" << endl;
    }
    break;
    case 3:
    cout << "You're a loser" << endl;
    break;
    case 4:
    cout << "I like pie" << endl;
    break;
    case 5:
    cout << "I like so muche MORE pie then you can imagine" << endl;
    break;
    default:
    cout << ".....";
    cin.get();
    }
    }
    }
}
btw. I have a few things includeed for no reason.
Your call to cin.get(); is within the default case of the switch.
Last edited on
Oh. Duh.....haha
Topic archived. No new replies allowed.