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 Jon Z. · September 10, 2015
also insted of
if()
{
}
else
{
if()
{
}
else
{
}
//...
}


use 

if()
{
}
else if()
{
}
else if()
{
}
else
{
}
0 Jon Z. · September 10, 2015
specify what the problem you are encountering is.

get rid of the \n in scanf


scanf(" %c", &r);
  • 1
  • 2

C

107,024 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator