This is a c code I have so far but seems couldnt find the pr

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<<\": \" << \"\\t\" << \"Dice_1 - \"<<roll1 << \" | Dice_2 - \"<<roll2;

cout << \" |Total = \" << (roll1 + roll2)<< \"\\t\";

checkWin(roll1, roll2);

cout<< endl;

}

cout<<\"===================================# Results #=============================================\"<<endl;

cout<< \"Total Played: \"<<\"\\t\"<< execute<<\" times\"<<endl;

cout<< \"Snake eyes rolled: \"<<\"\\t\"<< SnakeEyes<<\" times\"<<\"(\"<< checkPercentage(SnakeEyes, execute)<<\" Percent)\" <<endl;

cout<< \"Ace Deuce rolled: \"<<\"\\t\"<< AceDeuce<<\" times\"<<\"(\"<< checkPercentage(AceDeuce, execute)<<\" Percent)\" <<endl;

cout<< \"Seven Out rolled: \"<<\"\\t\"<< SevenOut<<\" times\"<< \"(\"<< checkPercentage(SevenOut, execute)<<\" Percent)\" <<endl;

cout<< \"Yo rolled: \"<<\"\\t\"<< Yo<<\" times\" <<\"(\"<< checkPercentage(Yo, execute)<<\" Percent)\" <<endl;

cout<< \"Boxcars rolled: \"<<\"\\t\"<< Boxcars<<\" times\" <<\"(\"<< checkPercentage(Boxcars, execute)<<\" Percent)\" <<endl;

return 0;

}

Solution

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;

}

This is a c++ code I have so far, but seems couldn\'t find the proper percentage for the each variable. Try input \
This is a c++ code I have so far, but seems couldn\'t find the proper percentage for the each variable. Try input \
This is a c++ code I have so far, but seems couldn\'t find the proper percentage for the each variable. Try input \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site