Question

In: Computer Science

Inside a do while loop ask a user to enter two numbers (use a single scanf...

Inside a do while loop ask a user to enter two numbers (use a single scanf function). Inside
the same loop ask the user whether they wish to find the min or max of the values entered. If
the user enters a 0 call the minFunction; if the user enters a 1 call the maxFunction; otherwise
print Not valid input. Pass the two first numbers entered as parameters to the functions. Inside
minFunction and maxFunction calculate the minimun and the maximum values, respectively.
Break the loop when the user enters -999 -999

in c please

Solutions

Expert Solution

Solution

Code

#include <stdio.h>

//max and min function declarations
int max(int number1, int number2);
int min(int number1, int number2);

int main()
{
int number1, number2, maximum, minimum,choice;//variable declaration
do
{
printf("\nEnter any two numbers:\n");
scanf("%d%d",&number1,&number2);//user input for two numbers
printf("\nEnter your choice : 0 for minimum 1 for maximum\n");
scanf("%d",&choice);//user input for choice
if(choice==0)//if user enters 0 min function will be called
{
minimum = min(number1, number2);//calling min function
printf("Minimum = %d", minimum);
}
else if(choice==1)////if user enters 1 max function will be called
{
maximum = max(number1, number2);//calling max function
printf("Maximum = %d", maximum);
} // Call minimum function
else
printf("Not valid input");

}while(number1!=-999 && number2!=-999);//if user enters -999 -999 loop will be stopped
  
return 0;
}


//max function used to find maximum between two numbers.
int max(int number1, int number2)
{
return (number1 > number2 ) ? number1 : number2;
}

//min function used to find minimum between two numbers.
int min(int number1, int number2)
{
return (number1 > number2 ) ? number2 : number1;
}

Screenshot of the program

Output

--

If you need any further help, please specify, love to help

all the best

please upvote


Related Solutions

Java program Use Do-while Write a do-wile loop that asks the user to enter two numbers....
Java program Use Do-while Write a do-wile loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user whether he or she wishes to perform the operation again. If so, the loop should repeat, otherwise, it should terminate. Use Continue branching statement Write a program that reads an integer and display all the positive ODD numbers from 0 to n (integer entered by the user). Use CONTINUE...
Use a while(true) loop to ask the user to “Enter a non-negative integer (enter negative integer...
Use a while(true) loop to ask the user to “Enter a non-negative integer (enter negative integer to quit):” and store this into an int named n. If the user enters a negative int for n, the while loop is broken via the brake statement. Otherwise, in the remaining part of the while loop, use a for loop to compute the sum of the inverse factorials from 0 to n, that is sum = 1/0! + 1/1! + 1/2! + ....
Use a while(true) loop to ask the user the following 2 values “Enter a rate r...
Use a while(true) loop to ask the user the following 2 values “Enter a rate r =” “Enter a nonnegative integer (enter negative integer to quit):” If the user enters a negative int for n, the while loop is broken via the brake statement. Otherwise, in the remaining part of the while loop, use a for loop to compute the partial sum for the geometric series, namely 1 + r + rˆ2 + rˆ3 + . . . +rˆn. Use...
Use a while(true) loop to ask the user the following 2 values “Enter a value x...
Use a while(true) loop to ask the user the following 2 values “Enter a value x “ “Enter a nonnegative integer n (enter negative integer to quit): “ If the user enters a negative int for n, the while loop is broken via the brake statement. Otherwise, in the remaining part of the while loop, use a for loop to compute the partial sum for the Riemann zeta series for the geometric series, namely 1 + 2ˆ-x + 3ˆ-x +...
Use a for loop to ask a user to enter the grades of 5 courses. The...
Use a for loop to ask a user to enter the grades of 5 courses. The user should enter character values, e.g., A. Calculate the GPA of the user Hint: Convert the character values entered to numerals, e.g., A to 4 c programming help me please
C++ while loop Exercise Write a program that continues to ask the user to enter any...
C++ while loop Exercise Write a program that continues to ask the user to enter any set of numbers, until the user enters the number -1. Then display the total sum of numbers entered and their average. (note that you need to define a counter that counts how many numbers so the average = (sum/n) where n is your counter total. #include <iostream> using namespace std; int main() { int number, n=0, sum=0; cout << "Enter a number to start...
using MIPs assembly, ask the user to enter two numbers. Then multiply the two numbers using...
using MIPs assembly, ask the user to enter two numbers. Then multiply the two numbers using bit shifting (not 'mul'). This should work multiplying 2 positive numbers, 2 negative numbers, and a positive/negative number. Then output the result and ask user if he/she has more calculations to complete.
Write a MIPS program that will ask the user to enter two numbers at the console...
Write a MIPS program that will ask the user to enter two numbers at the console and pass the values to a function that does multiplication
in MIPS assembly, ask a user for two numbers and to either enter a '1' for...
in MIPS assembly, ask a user for two numbers and to either enter a '1' for addition or '2' for subtraction. using jal, jump to the appropriate procedure for additing or subtracting. then print out result and ask if there is another calculation (terminate program if 'no').
USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The...
USE PYTHON. Create a program that will ask a user to enter whole positive numbers. The program will use a while loop to let the program keep running. The user will be allowed to use the program as long as the quitVariable is equal to 'y' or 'Y'. When the user decides to quit playing, say "Thanks for playing!". The program will use a for loop to test if the number are even or odd. If even print "number is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT