Create a two playerchange-counting game where the user will supply the number of
ID: 3673672 • Letter: C
Question
Create a two playerchange-counting game where the user will supply the number of coins (pennies, nickets, dimes, quarters) required to make a specific dollar amount. Player 1 will supply the total that player 2 will answer. If player 2 gets the correct amount, the program should congratulate the user for winning the game. Otherwise, the program should display a mesage indicating whether the amount entered was more or less than the required amount. Please include your algorithm as comment lines in your codeExplanation / Answer
#include<iostream.h>
#include<conio.h>
void main()
{
int p=0,d=0,q=0,di=0,n=0,re=0,p2,d2,q2,n2; //declaring and initalizing variables
double dd;
cout<<"Player 1 Please Enter amount in Dollers";
cin>>dd;
p=dd*100;
d=p/100;
re=p%100;
if(re>=25)
{
q=re/25;
re=re%25;
}
if(re>=10)
{
di=re/10;
re=re%10;
}
if(re>=5)
{
n=re/5;
re=re%5;
}
if(re>=1)
{
p=re;
}
cout<<"Okay, Player 2 Please enter the number of"<<endl;
cout<<"pennies";
cin>>p2;
cout<<"nickel";
cin>>n2;
cout<<"dime";
cin>>d2;
cout<<"quarters";
cin>>q2;
if(p2==p && n2==n && d2==di && q2 == q)
cout<<"Congratulations Player 1 you WIN";
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.