#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
//#include <string>
#include <ctype.h>
#include <time.h>
#include <math.h>
#include <iostream>
//using namespace std;
void menu();
char get_choice();
void ChangeUtl();
void HighLow();
void menu(int CCC, int HLC, int HLT)
{
system("cls");
int HLA = 0;
if (HLC != 0)
{
HLA = HLT / HLC;
}
else
std::cout<<"Used "<<CCC;
std::cout<<" Times"<<std::endl;
std::cout<<"Used "<<HLC;
std::cout<<" Times. Averaging "<<HLA;
std::cout<<" Tries."<<std::endl;
}
void main(int TTT)
{
char choice;
int CCC = 0;
int HLC = 0;
int HLT = 0;
do
{
menu(CCC, HLC, HLT);
choice = get_choice();
switch(choice)
{
case 'A':
CCC = CCC + 1;
ChangeUtl();
break;
case 'B':
HLC = HLC + 1;
HighLow();
break;
}
}
while(choice != 'Q');
}
char get_choice()
{
char ch;
do
{
ch = toupper(_getch());
}
while (!strchr("ABQ",ch));
return ch;
}
void ChangeUtl()
{
system("cls");
int pcd, ncd, dcd, qcd, hcd, totalc;
double pvd, nvd, dvd, qvd, hvd, total;
std::cout<<"Enter the Number of Pennies: ";
std::cin>>pcd;
std::cout<<std::endl;
std::cout<<"Enter the Number of Nickles: ";
std::cin>>ncd;
std::cout<<std::endl;
std::cout<<"Enter the Number of Dimes: ";
std::cin>>dcd;
std::cout<<std::endl;
std::cout<<"Enter the Number of Quarters: ";
std::cin>>qcd;
std::cout<<std::endl;
std::cout<<"Enter the Number of Half Dollar: ";
std::cin>>hcd;
std::cout<<std::endl;
pvd = pcd * 0.01;
nvd = ncd * 0.05;
dvd = ncd * 0.1;
qvd = qcd * 0.25;
hvd = hcd + 0.5;
total = pvd + nvd + dvd + qvd + hvd;
totalc = pcd + ncd + dcd + qcd + hcd;
std::cout<<"You Entered "<<pcd;
std::cout<<" Pennies for: $"<<pvd<<std::endl;
std::cout<<"You Entered "<<ncd;
std::cout<<" Nickels for: $"<<nvd <<std::endl;
std::cout<<"You Entered "<<dcd;
std::cout<<" Dimes for: $"<<dvd <<std::endl;
std::cout<<"You Entered "<<qcd;
std::cout<<" Quarters for: $"<<qvd<<std::endl;
std::cout<<"You Entered "<<hcd;
std::cout<<" Half Dollars for: $"<<hvd<<std::endl;
std::cout<<"You Entered "<<totalc;
std::cout<<" Coins worth a total of: $"<<total<<std::endl;
_getch();
}
void HighLow()
{
#define MAX 5
int magic, // number generated by the computer
guess, // players guess
tries = 0; // total number of guesses
srand( (unsigned)time( NULL ) ); // seed the random number table
magic = rand()%MAX; //return a random number from 0 to MAX
system("cls");
//printf("magic:%d ",magic); //this line can be used for debugging
printf("\n\nGuess the random number from 0 to %d\n",MAX
);
printf("Guess 9 to exit.\n\n\n");
do
{
scanf("%d",&guess);
if(guess == magic)
{
printf("%d is the magic number\n", magic
);
}
else
if(guess == 9)
{
magic = guess;
}
else
if (guess > magic)
printf(".. Wrong .. Too High\n");
else
printf(".. Wrong .. Too Low\n");
tries++;
} while(guess != magic);
HLT = HLT + tries;
printf("You took %d tries.\n", tries
);
printf("\n\n\n\nPress any key to end");
// modify this line so the user knows they are // returning to the menu and so I know you are
//reading this stuff ;)
_getch();
}