Write a program that outputs a subtraction practice problem for a student, outputting the larger random number
first and the smaller random number second.

this is in C++ and i cant figure it out

Respuesta :

Answer:

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

int main(void)

{

   srand(time(NULL));

   int num1, num2;

   int val;

   while (true)

   {

       num1 = rand() % 100 + 1; //Random number between 1-100

       num2 = rand() % 100 + 1; //Random number between 1-100

       if (num1 >= num2)

       {

           printf("%d - %d = ", num1, num2);

           scanf("%d",&val);

           if (val == num1-num2)

           {

               printf("Correct!\n");

           }

           else

           {

               printf("Incorrect!\n");

           }    

       }

       else

       {

           printf("%d - %d = ", num2, num1);

           scanf("%d",&val);

           if (val == num2-num1)

           {

               printf("Correct!\n");

           }

           else

           {

               printf("Incorrect!\n");

           }

       }    

   }

}

Explanation:

First, we create two random numbers and save the values.  Then we check to see which value is larger.  Based on that, we change how we display the format to the user.  Then we check to see if the user input number is equivalent to the subtraction problem.  If it is, we display Correct!  Else, we display Incorrect!

Cheers.