#include <windows.h>
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int Die_1 = 0, Die_2 = 0;
void RollDice()
{
Die_1 = (rand() % 6 ) + 1;
Die_2 = (rand() % 6 ) + 1;
}
int ComputerRolls()
{
RollDice();
return (Die_1 + Die_2);
}
int UserRolls()
{
char UserInput = 0;
std::cout<<"Press two to roll"<<std::endl;
cin>> UserInput;
cin.ignore();
if (UserInput == '2')
{
RollDice();
std::cout<<"You Rolled: "<<Die_1<<" And: "<<Die_2<<std::endl;
std::cout<<"For a grand total of: "<<Die_1 + Die_2<<std::endl;
return (Die_1 + Die_2);
}
return -1;
}
void WinnerResult(int UserResult, int ComputerResult)
{
if (UserResult == ComputerResult)
{
std::cout<<"You Tied with the computer!"<<std::endl;
}
else if (UserResult > ComputerResult)
{
std::cout<<"You Won!"<<std::endl;
}
else
std::cout<<"You Lost! The computer rolled a grand total of: "<<ComputerResult<<std::endl;
}
int main()
{
WinnerResult(UserRolls(), ComputerRolls());
}
triumphost
Practically a Master Poster
630 posts since Oct 2009
Reputation Points: 59
Solved Threads: 56
Skill Endorsements: 1
So,please tell me how do I store value of the first roll and compare it with the next move(s). I tried something, but it does not seem to work.
The same way to do it with any value -- create a variable to store the first roll and use that to compare all subsequent rolls.
WaltP
Posting Sage w/ dash of thyme
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37
You asked
So,please tell me how do I store value of the first roll and compare it with the next move(s).
I gave you a suggestion about how to do it. You responded with
@Waltp .. i am doing it here -
int result1 = compDice();
int result = userGame();
So what's the problem? Use those results and compare the subsequent rolls.
WaltP
Posting Sage w/ dash of thyme
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37
So what are you comparing above?
I suggest you change your variable names to something worthwhile. result and result1 are not indicative of their use. resultPerson and resultComputer define closer what the values hold -- but you can still come up with better names. Many times that helps you 'see' what you are trying to do.
You have something you've called a "first roll". What would be a good name for that variable? Do you need the "first roll" more than once? Is it important to keep the "first roll" separate from subsequent rolls? Plan accordingly.
WaltP
Posting Sage w/ dash of thyme
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37
Not going to any pastebin. If you can waste the time loading onto pastebin, you can certainly take less time and copy/paste your info here.
Did you make changes to the code? Do we know what the code looks like now?
WaltP
Posting Sage w/ dash of thyme
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37