This is a c++ code I have so far, but seems couldn\'t find the proper percentage
ID: 3921802 • Letter: T
Question
This is a c++ code I have so far, but seems couldn't find the proper percentage for the each variable.
Try input "1000"
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <time.h>
using namespace std;
int SnakeEyes=0 ,AceDeuce=0,SevenOut=0,Yo=0,Boxcars=0;
int execute=0;
void checkWin(int first_Roll, int second_Roll)
{int sum = first_Roll + second_Roll;
if (sum ==2)
{//Snake eyes- Lost
cout<<"|Snake eyes-Lost";
SnakeEyes++;
}
else if (sum ==3)
{//Ace Deuce - Lost
cout<<"|Ace Deuce- Lost";
AceDeuce++;
}
else if (sum ==7)
{//Seven Out- Win
cout<<"|Seven Out- WIN";
SevenOut++;
}
else if (sum ==11)
{//Yo-Win
cout<<"|YO- WIN";
Yo++;
}
else if (sum ==12)
{//Boxcars-Lost
cout<<"|Boxcars- Lost";
Boxcars++;
}
}
//Problem!
void checkPercentage(int item,int exc)
{
double percentage = (item /exc)*100;
return percentage;
}
int main()
{
int i=0;
time_t seconds;
time(&seconds);
int roll1,roll2;
srand((unsigned int)seconds);
while (execute<=0)
{cout << "Please input how many rolls you want to execute: ";
cin >> execute;
}
for (i=1; i<= execute ; i++)
{
roll1 = 1 + rand() % 6;
roll2 = 1 + rand() % 6;
cout << "Roll "<<i<<": " << " " << "Dice_1 - "<<roll1 << " | Dice_2 - "<<roll2;
cout << " |Total = " << (roll1 + roll2)<< " ";
checkWin(roll1, roll2);
cout<< endl;
}
cout<<"===================================# Results #============================================="<<endl;
cout<< "Total Played: "<<" "<< execute<<" times"<<endl;
cout<< "Snake eyes rolled: "<<" "<< SnakeEyes<<" times"<<"("<< checkPercentage(SnakeEyes, execute)<<" Percent)" <<endl;
cout<< "Ace Deuce rolled: "<<" "<< AceDeuce<<" times"<<"("<< checkPercentage(AceDeuce, execute)<<" Percent)" <<endl;
cout<< "Seven Out rolled: "<<" "<< SevenOut<<" times"<< "("<< checkPercentage(SevenOut, execute)<<" Percent)" <<endl;
cout<< "Yo rolled: "<<" "<< Yo<<" times" <<"("<< checkPercentage(Yo, execute)<<" Percent)" <<endl;
cout<< "Boxcars rolled: "<<" "<< Boxcars<<" times" <<"("<< checkPercentage(Boxcars, execute)<<" Percent)" <<endl;
return 0;
}
Explanation / Answer
you should use return type as the function is returning answer I.e.,percentage required as shown below..
double checkPercentage(int item,int exc)
{
double percentage = (item /exc)*100;
return percentage;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.