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...
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
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...
Use a sentinel while loop that repeatedly prompts the user to enter a number, once -1...
Use a sentinel while loop that repeatedly prompts the user to enter a number, once -1 is entered, stop prompting for numbers and display the maximum number entered by the user. I am struggling to have my program print the math function. Here is what I have so far: import java.util.*; public class MaxSentinel { public static void main(String[] args) {    Scanner input = new Scanner(System.in); System.out.println("Please enter a value. Press -1 to stop prompt."); int number = 0;...
I need to ask a user what numbers they want to enter. They can enter as...
I need to ask a user what numbers they want to enter. They can enter as many as they like. Then inside I need to use conditionals to determine if the numbers are <=20, <=323 && > 30, >200. I can't figure out how to let the user enter as many inputs as they want. I know I need to use a loop to check each number entered and determine if it is small middle or greater but I can't...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT