Making Simple Jackpot Game Using C++

What Is C++?

C++ is an object oriented programming language which gives focus on object rather than process.In c++ data can be hidden or can make it secrete.The main concept of object oriented programming(c++) is based on objects,which may contain data in the form of field often known as attributes and code.Many of the most widely used programming language that support object oriented programming includes C++,Java,PHP,C#,Ruby etc. C++ is statically typed,compiled,general purpose,case sensitive programming language that supports procedural,object oriented and generic programming.

Uses Of C++:

  • C++ is used  by thousand of programmer in essentially every application domain.
  • C++ is being used for teaching and research purpose.
  • It is easy to use and understand as well.

Making Simple Jackpot Project Game Using C++:

#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

void Start();
void GetResults();

int i, j, life, maxrand;
char c;

void Start() {
i = 0;
j = 0;
life = 0;
maxrand = 6;
cout << "Select difficulty mode:\n"; // the user has to select a difficutly level
cout << "1 : Easy (0-15)\n";
cout << "2 : Medium (0-30)\n";
cout << "3 : Difficult (0-50)\n";
cout << "or type another key to quit\n";
c = 30;

cin >> c;                   // read the user's choice
cout << "\n";

switch (c) {
case '1':
maxrand = 15;  // the random number will be between 0 and maxrand
break;
case '2':
maxrand = 30;
break;
case '3':
maxrand = 50;
break;
default:
exit(0);
break;
}

life = 5;         // number of lifes of the player
srand((unsigned)time(NULL)); // init Rand() function
j = rand() % maxrand;  // j get a random value between 0 and maxrand
GetResults();
}

void GetResults() {
if (life <= 0) { // if player has no more life then he loses
cout << "You lose !\n\n";
Start();
}

cout << "Type a number: \n";
cin >> i;
if((i>maxrand) || (i<0)) { // if the user number isn't correct, restart
cout << "Error: number not between 0 and \n" << maxrand;
GetResults();
}

if(i == j) {
cout << "YOU WIN!\n\n"; // the user found the secret number
Start();
} else if(i>j) {
cout << "Too BIG\n";
life = life - 1;
cout << "Lives remaining: " << life << "\n\n";
GetResults();
} else if(i<j) {
cout << "Too SMALL\n";
life = life - 1;
cout << "Lives remaining: " << life << "\n\n";
GetResults();
}
}

int main() {
cout << "** Jackpot game **\n";
cout << "The goal of this game is to guess a number.\n";
cout << "Jackpot will tell you if the number is too big or too\n";
cout << "small compared to the secret number to find.\n\n";
Start();
return 0;
}

Output:



This is the normal output of the above program you can change it by your own coding style also.It is the normal c++ program to make the jackpot game.You can play it by selecting the difficulties level as shown above and guessing the correct number to win the game  in the life of 4 otherwise you lose.


At last C++ is very useful programming language in every field.Through C++ small projects to large projects can be made.Every primary use interface of different systems like Apple,Macintosh,PC,is written in C++ so every person who use this system also use C++.It is regarded as Middle Level Language(MLL) as it comprise a combination of both High level language(HLL) and Low Level Language(LLL).It is also known as the super set of C.

Comments

Popular posts from this blog

How Central Processing Unit (CPU) Works?

What is CBIS(Computer Based Informaiton System)?

Corona virus (COVID-19) Myths.