Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update magic8_switch.cpp #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 69 additions & 46 deletions 3-conditionals-and-logic/magic-8-ball/magic8_switch.cpp
Original file line number Diff line number Diff line change
@@ -1,51 +1,74 @@
/*
C++ Program codecademy, magic8 balls, random fortune game
description :
1. random fortune game each time from 0 - 9
2. every declare a random number can print this output :
1) It is certain.
2) It is decidedly so.
3) Without a doubt.
4) Yes - definitely.
5) You may rely on it.
7) Ass I see it, yes.
8) Most likely.
9) Outlook good.
3. This program make an switch case concepts to make conditional
*/
#include <iostream>
#include <string>
#include <cstdlib>

int main() {

std::cout << "MAGIC 🎱 SAYS: \n\n";

srand(time(NULL));

int choice = std::rand() % 10;

switch(choice) {
case 0:
std::cout << "No. Not really.\n";
break;
case 1:
std::cout << "Val!\n";
break;
case 2:
std::cout << "You are an adult.\n";
break;
case 3:
std::cout << "Four R's, my friend: Reduce, reuse, recycle, Rihanna.\n";
break;
case 4:
std::cout << "Nomo FOMO.\n";
break;
case 5:
std::cout << "Yas.\n";
break;
case 6:
std::cout << "Work it, dawg!\n";
break;
case 7:
std::cout << "Carpe dayum!\n";
break;
case 8:
std::cout << "Cha-Chinga!\n";
break;
case 9:
std::cout << "Yaaaaas Kween!\n";
break;
default:
std::cout << "IDK.\n";
break;

}

return 0;
int main (){
std::cout << "================================\n";
std::cout << "Welcome to program fortune game \n";
std::cout << "Magic 8-BALL : \n";

srand(time(NULL));
int answer_number = std::rand() % 10;
std::string answer;

// Make conditional to print base of case answer_number
switch (answer_number){
case 1 :
answer = "It is certain.";
break;

case 2 :
answer = "It is decidedly so.";
break;

case 3 :
answer = "Without a doubt.";
break;

case 4 :
answer = "Yes - definitely.";
break;

case 5 :
answer = "You may rely on it.";
break;

case 6 :
answer = "As I see it, yes.";
break;

case 7 :
answer = "Most likely.";
break;

case 8 :
answer = "Outlook good.";
break;

case 9 :
answer = "Yes.";
break;

default :
answer = "Invalid fortune number.";
break;
}
std::cout << answer << "\n";
std::cout << "================================\n";
return 0;
}