Learning Objectives: More practice with user input/output, including string inpu
ID: 3742675 • Letter: L
Question
Learning Objectives: More practice with user input/output, including string input. Use of if/else, possibly nested, to solve simple problems. - General Description 1. Write a program that asks the user to enter 3 numbers, one at a time. Print the three numbers in sorted order. [Note: no need to use an array or similar structure!] Examples (user input in blue) Enter number1 45 Enter number 1: 55 Enter number 2: 45 Enter number 3: 35 Sorted they are 35 45 55 Enter number 2: 35 Enter number 3: 55 Sorted they are 35 45 55 2. In the same program Write code that will display the following menu: A. Aleppo Pepper B. Banana Pepper C. Cayenne Pepper D. Dragons Breath Enter a letter to choose a pepper: Calculate the Scoville Units (measure of hotness) Aleppo 30,000 Banana-1,000 Cayenne 40,000 Dragon's Breath 2,480,000 Print the Scoville Units for the chosen pepper, example That's 1000 Scovilles of heat! The program should handle both upper and lower case entries... that is 'A or 'a' should print the Scoville Units for the Aleppo. The program should print "That pepper is not on the list" when the user enters anything besides A, B, C, D (or a,b,c,d). You may assume the user will not enter blanks in their answer, but they may enter more than one character As always, the program should end with a pauseExplanation / Answer
#include<stdio.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
void main()
{
int a,b,c,low,high,middle;
printf(" Enter Number 1 : ");
scanf("%d",&a);
printf(" Enter Number 2 : ");
scanf("%d",&b);
printf(" Enter Number 3 : ");
scanf("%d",&c);
low = min(min(a, b), c);
high = max(max(a, b), c);
middle = a+b+c-low-high;
printf(" Sorted they are : %d %d %d ",low,middle,high);
char x;
printf(" A. Aleppo Pepper");
printf(" B. Banana Pepper");
printf(" C. Cayenne Pepper");
printf(" D. Dragons Pepper");
printf(" Enter a letter to choose a pepper : ");
scanf("%c",&x);
/*
Aleppo = 30,000
Banana = 1,000
Cayenne = 40,000
Dragon's Breath = 2,480,000
*/
if(x == 'a' || x == 'A')
printf(" That's 30000 scovilloes of heat");
else if(x == 'b' || x == 'B')
printf(" That's 1000 scovilloes of heat");
else if(x == 'c' || x == 'C')
printf(" That's 40000 scovilloes of heat");
else if(x == 'd' || x == 'D')
printf(" That's 2480000 scovilloes of heat");
else
printf(" That pepper is not on the list") ;
getchar();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.