0

iam working on a project and im kind of stuck. my code is supposed to show some additions divisions and multiplications , and the user has to find the coreect result. I want to show "Right" when he's right and Error when he's not. I've gotten it to work i think , but it shows the same equation over and over. Eg 5-2 user presses 3 , "Right", and then the same thing over and over. What im trying to do is show something different every time for example 5-2=2 "Error" 7+2=9 "Right" etc

Here's what i've come up with so far. Hope you can help me understand what i'm doing wrong in this.

#include <stdlib.h>
#include<stdio.h>
int main (void){
    int temp,i=0,n2,n1,c,N,N1,N2,num1,num2;
    do {
        srand(4675);
    
    num1=rand()%20+1;
    num2=rand()%30+1;
    N1=rand()%30+1;
    N2=rand()%40+1;
    n1=rand()%100+100;
    n2=rand()%120+100;
    c=rand()%4;
        i++;
        switch(c) {
            case 0:
                printf("%d+%d",n1,n2);
            scanf("%d",&N);
            if (N==n1+n2)
            printf("Right\n");
            else printf ("Error\n");
            break;
            case 1:
            if (n1>n2)
            printf("%d-%d",n1,n2);
            else if (n2>n1)
            printf("%d-%d",n2,n1);
            scanf ("%d",&N);
            if (N==n1-n2 || N==n2-n1)
            printf("Right\n");
            else printf("Error\n");
            break;
            case 2:
                printf("%d*%d",N1,N2);
            scanf("%d",&N);
            if (N==N1*N2)
                printf("Right\n");
            else printf("Error\n");
            break;
            case 3:
                printf("%d/%d",num1,num2);
                scanf("%d",&N);
                if (N==num1/num2)
                printf("Right\n");
                else printf("Error\n");
                break;
                
        }
        
    }
while (i<10);
        return 0;}

Ted
  • 3
  • 4

0 Answers0