Write a C code for a casino came In this guessing game playe
Write a C++ code for a casino came. In this guessing game player can deposit his money to play. From this amount he can bet on number between 1 to 10. If he win he gets 10 times of money otherwise lost his money.
The program must include:
1) At least one if statement.
2) At least one switch statement.
3) At least 2 of the 3 of the following: For, While, and DoWhile loops.
4) An array or a vector.
5) at least 2 functions.
6) Comments
Solution
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int numbers[10]; //array contains 1 to 10 numbers for program to select for guessing game
void createArray();
bool Win(int,int);
int Rand(int);
int main()
{
int amount;
int guess;
bool check;
int random_number;
createArray();
cout<<\"Enter your amount\\t\"; //program ask for user amount
cin>>amount;
cout<<\"Enter your number 1-10\\t\"; //program ask for user number
cin>>guess;
random_number=numbers[Rand(guess)%10]; //program will generate some random number using Rand and then will divide
//the random number with 10 and use that number as array subscript and fetch
//the number from array
check=Win(guess,random_number); //method will return true or false means whether he wins game or not
switch(check)
{
case true: //if true it means he wins game and
amount=amount*10; //amount has been increased by 10 times
cout<<\"Your amount=\\t\"<<amount;
break;
case false:
amount=0; //he lose the game
cout<<\"Your amount=\\t\"<<amount;
break;
}
}
bool Win(int guess,int random_number) //this method will compare program generated number and user number
{
if(guess==random_number) //if matches return true
{
return true;
}
else{
return false; //otherwise return false
}
}
void createArray() //this method will create array and place numbers from 1 to 10
{ // program will use this array to pick random number
int k=0;
for(int i=0;i<=9;i++)
{
k++;
numbers[i]=k;
}
}
int Rand(int guess) //this is the method which will generate some random number
{
int prime=37;
while(guess>0)
{
prime=prime+guess;
guess--;
}
return prime;
}

