fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <math.h>
  6.  
  7. int main()
  8. {
  9. char letters[6] = {'l', 's', 'h', 'L', 'S', 'H'};
  10. char decision;
  11. char choice;
  12. char result1;
  13. char result2;
  14. int i;
  15. int digit=0;
  16. int sum1=0;
  17. int sum2=0;
  18.  
  19. //printf("%c %c %c %c %c %c", letters[0], letters[1], letters[2], letters[3], letters[4], letters[5]);
  20. for(i=0; i<=2; i++){
  21. digit = (rand()%6)+1;
  22. //printf("%d \n", digit);
  23. sum1=sum1+digit;
  24. //printf("%d \n", sum1);
  25. }
  26. printf("\nThe sum of drawn digits is: %d", sum1);
  27. printf("\nTry to guess what the next number will be: ");
  28. printf("\nFor lower press 'L'.");
  29. printf("\nIf you think the same press 'S'.");
  30. printf("\nFor higher press 'H'.\n");
  31. COMEBACK:scanf(" %c", &decision);
  32.  
  33. if(decision==letters[0] || decision==letters[1] || decision==letters[2] || decision==letters[3] || decision==letters[4] || decision==letters[5]){
  34. digit=0;
  35. for(i=0; i<=2; i++){
  36. digit = (rand()%6)+1;
  37. //printf("%d \n", digit);
  38. sum2=sum2+digit;
  39. //printf("%d \n", sum2);
  40. }
  41. if(sum1>sum2){
  42. result1='l';
  43. result2='L';
  44. }
  45. else if(sum1==sum2){
  46. result1='s';
  47. result2='S';
  48. }
  49. else{
  50. result1='h';
  51. result2='H';
  52. }
  53. if(decision==result1 || decision==result2){
  54. printf("\nYou are right!");
  55. }
  56. else{
  57. printf("\nYou are wrong!");
  58. }
  59. }
  60. else{
  61. printf("\nYou pressed wrong button!");
  62. printf("\nDo you want try enter your choice again? (y/n): " );
  63. scanf(" %c", &choice);
  64. switch(choice){
  65.  
  66. case 'y' : printf("\nEnter your choice again: ");
  67. goto COMEBACK;
  68.  
  69. case 'n' : printf("\nSee you soon");
  70. break;
  71.  
  72. default : printf("\nI do not know what does this mean. Bye!");
  73. break;}
  74.  
  75. }
  76.  
  77. return 0;
  78. }
  79.  
Success #stdin #stdout 0s 2056KB
stdin
l
stdout
The sum of drawn digits is: 11
Try to guess what the next number will be: 
For lower press 'L'.
If you think the same press 'S'.
For higher press 'H'.

You are right!