1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <string.h>
  5. //#include <string>
  6. #include <ctype.h>
  7. #include <time.h>
  8. #include <math.h>
  9. #include <iostream>
  10. //using namespace std;
  11.  
  12.  
  13. void menu();
  14. char get_choice();
  15. void ChangeUtl();
  16. void HighLow();
  17.  
  18.  
  19. void menu(int CCC, int HLC, int HLT)
  20. {
  21. system("cls");
  22. int HLA = 0;
  23.  
  24. if (HLC != 0)
  25. {
  26. HLA = HLT / HLC;
  27. }
  28. else
  29.  
  30. printf( "A. Change Count ");
  31. std::cout<<"Used "<<CCC;
  32. std::cout<<" Times"<<std::endl;
  33. printf( "B. High Low ");
  34. std::cout<<"Used "<<HLC;
  35. std::cout<<" Times. Averaging "<<HLA;
  36. std::cout<<" Tries."<<std::endl;
  37. printf( "Q. Quit Program\n");
  38. printf( "\n\n\n" );
  39. printf( ":" );
  40. }
  41.  
  42. void main(int TTT)
  43. {
  44. char choice;
  45. int CCC = 0;
  46. int HLC = 0;
  47. int HLT = 0;
  48. do
  49. {
  50. menu(CCC, HLC, HLT);
  51. choice = get_choice();
  52. switch(choice)
  53. {
  54. case 'A':
  55. CCC = CCC + 1;
  56. ChangeUtl();
  57. break;
  58. case 'B':
  59. HLC = HLC + 1;
  60. HighLow();
  61. break;
  62. }
  63. }
  64. while(choice != 'Q');
  65. }
  66.  
  67. char get_choice()
  68. {
  69. char ch;
  70. do
  71. {
  72. ch = toupper(_getch());
  73. }
  74. while (!strchr("ABQ",ch));
  75. return ch;
  76. }
  77.  
  78. void ChangeUtl()
  79. {
  80. system("cls");
  81. int pcd, ncd, dcd, qcd, hcd, totalc;
  82. double pvd, nvd, dvd, qvd, hvd, total;
  83.  
  84. std::cout<<"Enter the Number of Pennies: ";
  85. std::cin>>pcd;
  86. std::cout<<std::endl;
  87. std::cout<<"Enter the Number of Nickles: ";
  88. std::cin>>ncd;
  89. std::cout<<std::endl;
  90. std::cout<<"Enter the Number of Dimes: ";
  91. std::cin>>dcd;
  92. std::cout<<std::endl;
  93. std::cout<<"Enter the Number of Quarters: ";
  94. std::cin>>qcd;
  95. std::cout<<std::endl;
  96. std::cout<<"Enter the Number of Half Dollar: ";
  97. std::cin>>hcd;
  98. std::cout<<std::endl;
  99.  
  100. pvd = pcd * 0.01;
  101. nvd = ncd * 0.05;
  102. dvd = ncd * 0.1;
  103. qvd = qcd * 0.25;
  104. hvd = hcd + 0.5;
  105. total = pvd + nvd + dvd + qvd + hvd;
  106. totalc = pcd + ncd + dcd + qcd + hcd;
  107.  
  108. std::cout<<"You Entered "<<pcd;
  109. std::cout<<" Pennies for: $"<<pvd<<std::endl;
  110. std::cout<<"You Entered "<<ncd;
  111. std::cout<<" Nickels for: $"<<nvd <<std::endl;
  112. std::cout<<"You Entered "<<dcd;
  113. std::cout<<" Dimes for: $"<<dvd <<std::endl;
  114. std::cout<<"You Entered "<<qcd;
  115. std::cout<<" Quarters for: $"<<qvd<<std::endl;
  116. std::cout<<"You Entered "<<hcd;
  117. std::cout<<" Half Dollars for: $"<<hvd<<std::endl;
  118. std::cout<<"You Entered "<<totalc;
  119. std::cout<<" Coins worth a total of: $"<<total<<std::endl;
  120.  
  121.  
  122.  
  123. _getch();
  124. }
  125.  
  126. void HighLow()
  127. {
  128. #define MAX 5
  129. int magic, // number generated by the computer
  130. guess, // players guess
  131. tries = 0; // total number of guesses
  132.  
  133. srand( (unsigned)time( NULL ) ); // seed the random number table
  134. magic = rand()%MAX; //return a random number from 0 to MAX
  135. system("cls");
  136. //printf("magic:%d ",magic); //this line can be used for debugging
  137. printf("\n\nGuess the random number from 0 to %d\n",MAX);
  138. printf("Guess 9 to exit.\n\n\n");
  139. do
  140. {
  141. printf("Guess: ");
  142. scanf("%d",&guess);
  143. if(guess == magic)
  144. {
  145. printf("** Right **");
  146. printf("%d is the magic number\n", magic);
  147. }
  148. else
  149. if(guess == 9)
  150. {
  151. magic = guess;
  152. printf("Quiting......");
  153. }
  154. else
  155. if (guess > magic)
  156. printf(".. Wrong .. Too High\n");
  157. else
  158. printf(".. Wrong .. Too Low\n");
  159. tries++;
  160. } while(guess != magic);
  161.  
  162. HLT = HLT + tries;
  163.  
  164. printf("You took %d tries.\n", tries);
  165. printf("\n\n\n\nPress any key to end"); // modify this line so the user knows they are
  166. // returning to the menu and so I know you are
  167. //reading this stuff ;)
  168. _getch();
  169. }
  170.