Coupon + Question on random statements

closed account (367kGNh0)
Hello,

Firstly I wanted to share this free c++ udemy course coupon worth £9.99. :

https://www.udemy.com/cpp-course/?couponCode=CPP_FREE you should paste it into the URL bar.

Another if you are interested in cocos 2d game development!

https://www.udemy.com/cocos2d-x-v3-cpp/?couponCode=CCDX-FREE again you should paste it into the URL bar.


now to my C++ question, In the world of app development, while experimenting I wondered, is this how they get their app to generate random words(for example the caption during a loading screen):

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
#include<iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int main () {
	
	srand(time(0));
	int Juki = 1+rand()%9;
		
	Juki;
	
	if(Juki == 1)
	{cout<<"We are gonna do Diving";}
	
	else if(Juki == 2)
	{cout<<"We are gonna do Lapping";}
	
	else if(Juki == 3)
	{cout<<"We are gonna do Cannonballing";}

	else if (Juki == 4)
	{cout<<"We are gonna do Butterfly kicking";}
	
	else if (Juki == 5)
	{cout<<"We are gonna do Paddling";}
	
	else if (Juki == 6)
	{cout<<"We are gonna do Swimming";}
	
	else if (Juki == 7)
	{cout<<"We are gonna do sidestroke";}
	
	else if (Juki == 8)
	{cout<<"We are gonna do front crawl";}
	
	else if (Juki == 9)
	{cout<<"We are gonna do breast stroke";}
	
		
	
	return 0;
}

Hello Rascake,

Line 11 does nothing. The if/elst if statements would work better in a switch.

Untested, but it looks like it should work. Not sure what you have in mind for the rest of "main", but a start.

Andy
Recognise the array possibilities.
1
2
3
4
5
6
7
8
9
10
11
12
const char *activities[] = {
    "Diving",
    "Lapping",
    "Cannonballing",
    "Butterfly kicking",
    "Paddling",
    "Swimming",    
    "sidestroke",
    "front crawl",
    "breast stroke",
};
cout<<"We are gonna do " << activities[rand()%9];

closed account (367kGNh0)
Thank you salem! And thanks for the note on line 11 andy
Topic archived. No new replies allowed.