1. Write a program that produces the output shown below: 2. Include four functions: getNumber The function prompts the user to enter a float value o The value entered by the user is returned to main()

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

My Program doesn't let me enter an input for choice it automatically skips to Invalid choice. 

 

Program is written in C++

Hw 7a-2
1. Write a program that produces the output shown below:
2. Include four functions:
getNumber
The function prompts the user to enter a float value
The value entered by the user is returned to main()
showMenu
o The function display a menu of choices (A and B)
No value is returned to main()
getChoice
o The function prompts the user to enter a choice (A or B)
o The value entered by the user is returned to main()
showResult
o The function displays the result
If the user entered a or A, the function displays the number and its square.
5.00 squared equals 25.00
If the user entered b or B, the funtion displays the number and its square root.
The square root of 5.00 equals 2.24.
But if the user enters any other character, the function displays:
Invalid choice.
Must be A or B.
Now closing
/* OUTPUT
Enter a float value:
5
А.)
В.)
Calculate the
square.
Calculate the square root.
Enter your choice:
5.00 squared equals 25.00.
(or)
a
Enter a float value:
5
Calculate the square.
А.)
В.)
Calculate the square root.
Enter your choice:
The square root of 5.00 equals 2.24.
(or)
b
Enter a float value:
5
А.)
Calculate the
square.
В.)
Calculate the square root.
Enter your choice:
Invalid choice.
Must be A or B.
Now closing.*/
Transcribed Image Text:Hw 7a-2 1. Write a program that produces the output shown below: 2. Include four functions: getNumber The function prompts the user to enter a float value The value entered by the user is returned to main() showMenu o The function display a menu of choices (A and B) No value is returned to main() getChoice o The function prompts the user to enter a choice (A or B) o The value entered by the user is returned to main() showResult o The function displays the result If the user entered a or A, the function displays the number and its square. 5.00 squared equals 25.00 If the user entered b or B, the funtion displays the number and its square root. The square root of 5.00 equals 2.24. But if the user enters any other character, the function displays: Invalid choice. Must be A or B. Now closing /* OUTPUT Enter a float value: 5 А.) В.) Calculate the square. Calculate the square root. Enter your choice: 5.00 squared equals 25.00. (or) a Enter a float value: 5 Calculate the square. А.) В.) Calculate the square root. Enter your choice: The square root of 5.00 equals 2.24. (or) b Enter a float value: 5 А.) Calculate the square. В.) Calculate the square root. Enter your choice: Invalid choice. Must be A or B. Now closing.*/
float getNumber();
void showMenu ();
char getChoice ();
void showResult(float number, char choice);
eint main()
float number;
char choice;
number = getNumber();
showMenu ();
getChoice();
showResult (number, choice);
choice =
return 0;
Efloat getNumber()
{
float number;
cout << "Enter a float value: ";
cin >> number;
return number;
Evoid showMenu()
Calculate the square.\n"
cout << "A.)
<< "B.) Calculate the square root.\n";
achar getChoice()
char choice;
cout << "Enter your choice: ";
cin.get (choice);
return choice;
Evoid showResult (float number, char choice)
if (choice == 'a' [| choice == 'a')
{
cout << number <<
squared equals
« pow(number, 2) <« ".\n\n";
else if (choice
'b' || choice == 'B')
==
{
cout << number <<
squared equals
<« sqrt(number) « ".\n\n";
else
{
cout << "Invalid choice. Must be A or B.\n";
}
Transcribed Image Text:float getNumber(); void showMenu (); char getChoice (); void showResult(float number, char choice); eint main() float number; char choice; number = getNumber(); showMenu (); getChoice(); showResult (number, choice); choice = return 0; Efloat getNumber() { float number; cout << "Enter a float value: "; cin >> number; return number; Evoid showMenu() Calculate the square.\n" cout << "A.) << "B.) Calculate the square root.\n"; achar getChoice() char choice; cout << "Enter your choice: "; cin.get (choice); return choice; Evoid showResult (float number, char choice) if (choice == 'a' [| choice == 'a') { cout << number << squared equals « pow(number, 2) <« ".\n\n"; else if (choice 'b' || choice == 'B') == { cout << number << squared equals <« sqrt(number) « ".\n\n"; else { cout << "Invalid choice. Must be A or B.\n"; }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Types of Loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education