Hello all this is my first post and I have been lurking about since I have found this site. So here is my dilemma, I have a problem for school that will generate 3 random numbers between 0 and 9. GOT THAT I THINK.. it allows for users to pick 3 random numbers and compare them to the ones that have been generated. The awards are as follows: any one matching = $10, two matching = $100, three matching not in order = $1000, and three matching in order = $1,000,000. So I'm having an issue with my if statements so that they cover all the bases. I would love some feedback and what I can do to better the code that I have done since I am a newbie. should I make a struct for numbers like for guesse, generated, ? something along those lines?
Here is what I have:
Code:
// lottery.cpp : main project file.
#include "stdafx.h"
#include <iostream>
#include <ctime>
using namespace std;
int main ()
{
// Declare variables
int firstGuess,
secondGuess,
thirdGuess,
firstResult,
secondResult,
thirdResult;
cout << "This is a lottery game that allows the user to pick three numbers." << endl;
cout << "The game will randomly pick three numbers as well.." << endl;
cout << "The winnings will be based on the matching of the correct numbers picked." << endl;
cout << "Any one matching = $10, Any two matching = $100," << endl;
cout << "Any three matching, not in order = $1,000." << endl;
cout << "Three matching in exact order = $1,000,000, No matches = $0." << endl;
cout << "Now the fun begins.. GOOD LUCK !!!" << endl;
cout << "Please pick your first number: ";
cin >> firstGuess;
cout << "Please pick your second number: ";
cin >> secondGuess;
cout << "Pleas pick your third number: ";
cin >> thirdGuess;
cout << "Your picked numbers are: " << firstGuess << "--" << secondGuess <<"--" << thirdGuess << endl;
cout << endl;
cout << endl;
cout << "And the winning numbers are.... " <<endl;
// Now draw the winning three numbers
const int DIVISOR = 10;
const int NUM = 3;
srand ((unsigned) time (NULL));
{
firstResult = rand() % DIVISOR;
secondResult = rand() % DIVISOR;
thirdResult = rand() % DIVISOR;
};
cout << firstResult <<"--" << secondResult <<"--" << thirdResult << endl;
cout << endl;
if (firstGuess == firstResult && secondGuess == secondResult && thirdGuess == thirdResult)
cout << "YOU WIN THE GRAND PRIZE!!!! $1,000,000 " << endl;
if (firstGuess == firstResult || firstGuess == secondResult || firstGuess == thirdResult
|| secondGuess == firstResult || secondGuess == secondResult || secondGuess == thirdResult
|| thirdGuess == firstResult || thirdGuess == secondResult || thirdGuess == thirdResult)
cout << "You win $1,000 " << endl;
if (firstGuess == firstResult || firstGuess == secondResult || firstGuess == thirdResult
&& secondGuess == firstResult || secondGuess == secondResult || secondGuess == thirdResult
&& thirdGuess == firstResult || thirdGuess == secondResult || thirdGuess == thirdResult)
cout << "You win $100 " << endl;
return 0;
}