Can you tell me what's wrong with this program? PLEASE!

+2 Sandra T · September 9, 2015
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>


 int main()
{
  int a,b,ok,no;
  char r;
  ok=no=0; a=0; b=0;
  printf("WELCOME! YOUR FIRST SUM OF 3 NR. IS ");
  a=((rand()%6)+1)+((rand()%6+1)+1)+((rand()%6)+1);
  printf(" %d\n", a);
  printf("HOW WILL BE THE NEXT?\nPRESS:\nh-FOR HIGHER\nl-FOR LOWER\ns-FOR THE SAME\ne-FOR EXIT GAME\n");

 do {
    scanf(" %c\n", &r);
    b=((rand()%6)+1)+((rand()%6)+1)+((rand()%6)+1);
    if (r=='s')  {if (a==b) {printf("GREAT!\n"); ok++; break;}else{printf("STUPID\n!"); no++; }
                 }else{ if (r=='h') {if (b>a) {printf("GREAT!\n"); ok++; break;}else{printf("STUPID!\n"); no++; }
                                   }else{if (r=='l') {if (b<a) {printf("GREAT!\n"); ok++; break;}else{printf("STUPID!\n"); no++; }
                                         }else{printf("READ THE RULES!\n");}}}
  printf("HOW WILL BE THE NEXT?\n");

  a=b;
  }while(r=='s' || r=='l' || r=='h');
  printf("END OF GAME!\nGOOD POINTS: %d\nBAD POINTS: %d ", ok,no);
 return 0;
}

Post a Reply

Replies

- page 2
Oldest  Newest  Rating
0 Saket Kulkarni · September 12, 2015
Hey Sandra.... I'm not getting the objective of the program. Is it one of Bucky's Tutorials??
0 Sandra T · September 12, 2015
The challenge#2 is in Bucky's tutorial number 38 (C programming).
  • 1
  • 2

C

107,101 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator