Learning Objectives: More practice with user input/output, including string inpu
ID: 3743162 • 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<iostream>
#include<conio.h>
using namespace std;
int main()
{
string str;
int a=0,b=0,c=0,small=1,mid=2,big=3; //small for smallest, mid for middle, big for biggest
cout<<"Enter 3 numbers to sort them"<<endl;
cout<<"Enter number 1"<<endl;
cin>>a;
cout<<"Enter number 2"<<endl;
cin>>b;
cout<<"Enter number 3"<<endl;
cin>>c;
if ((a < b) && (a < c))
{
small = a;
if (b > c)
{
big = b;
mid = c;
}
}
if ((a < b) && (c < a))
{
small = a;
if (b < c)
{
mid = b;
big = c;
}
}
if ((a > b) && (c > a))
{
mid = a;
if (b < c)
{
small = b;
big = c;
}
}
if ((a < b) && (c < a))
{
mid = a;
if (b > c)
{
big = b;
small = c;
}
}
if ((a > b) && (a > c))
{
big = a;
if (c > b)
{
mid = c;
small = b;
}
}
if ((a > b) && (a > c))
{
big = a;
if (b > c)
{
mid = b;
small = c;
}
}
cout<<"Sorted they are "<<small<<" "<<mid<<" "<<big<<endl;
cout<<"A. Aleppo Pepper B. Banan Pepper C. Cayenne Pepper D. Dragons Breath Enter a letter to choose a pepper:"<<endl;
cin>>str;
if(str=="a" || str=="A")
{
cout<<"That's 30,000 Scovilles of heat!"<<endl;
}
else if(str=="b" || str=="B")
{
cout<<"That's 1,000 Scovilles of heat!"<<endl;
}
else if(str=="c" || str=="C")
{
cout<<"That's 40,000 Scovilles of heat!"<<endl;
}
else if(str=="d" || str=="D")
{
cout<<"That's 2,480,000 Scovilles of heat!"<<endl;
}
else
{
cout<<"That pepper is not on the list"<<endl;
}
getch();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.