So I am supposed to essentially make this game in which I randomly generate a predetermined set of 4 numbers that (with the addition of operators by the user)would ideally evaluate to 24. The program works perfect but when I ask the user whether or not he wants to play again....
if Y is typed in, the program runs again and just all of sudden close (<- This is the problem)
if N is typed in, the program closes (which is expected)
The issue I need help with is: Where/how would I edit the program so that the program runs again every time the user indicates that it should with the entering of Y, instead of just twice..
That you so much for your assistance!
if Y is typed in, the program runs again and just all of sudden close (<- This is the problem)
if N is typed in, the program closes (which is expected)
The issue I need help with is: Where/how would I edit the program so that the program runs again every time the user indicates that it should with the entering of Y, instead of just twice..
That you so much for your assistance!
#include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int a,b,c=0; char typeIn='Y'; do { int q,w,e,r=0; char op1,op2,op3; srand(time(NULL)); switch(rand()%3) { case 0: printf("these nums %d, %d, %d, %d\n",8,5,8,1); q=8; w=5; e=8; r=1; break; case 1: printf("these nums %d, %d, %d, %d\n",5,1,6,1); q=5; w=1; e=6; r=1; break; case 2: printf("these nums %d, %d, %d, %d\n",7,8,8,2); q=7; w=8; e=8; r=2; break; case 3: printf("these nums %d, %d, %d, %d\n",9,3,4,1); q=9; w=3; e=4; r=1; break; case 4: printf("these nums %d, %d, %d, %d\n",9,5,2,2); q=9; w=5; e=2; r=2; break; case 5: printf("these nums %d, %d, %d, %d\n",8,6,4,2); q=8; w=6; e=4; r=2; break; } printf("\nyour operators please:"); scanf("%c%c%c",&op1,&op2,&op3); if(op1=='+') a=q+w; else if (op1=='-') a=q-w; else if (op1=='/') a=q/w; else if (op1=='*') a=q*w; printf("%d %c %d is: %d\n",q,op1,w,a); if(op2=='+') b=a+e; else if (op2=='-') b=a-e; else if (op2=='/') b=a/e; else if (op2=='*') b=a*e; printf("%d %c %d is: %d\n",a,op2,e,B)/>; if(op3=='+') c=b+r; else if (op3=='-') c=b-r; else if (op3=='/') c=b/r; else if (op3=='*') c=b*r; printf("%d %c %d is: %d\n\n",b,op3,r,c); if (c==24) { printf("sweet\n"); } else printf("you're wrong\n"); printf("Tryagain?\n"); scanf(" %c",&typeIn); } while (typeIn=='Y'||typeIn=='y'); }