Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++: devcpp Use appropriate commenting and indenting style. Write one program that solves two problems about nutrition: calculate a restaurant bill and calculate your body

C++: devcpp Use appropriate commenting and indenting style. Write one program that solves two problems about nutrition: calculate a restaurant bill and calculate your body mass index (BMI). The steps are: 1) Restaurant bill - write code that calculates a restaurant bill given cost of food and tip percentage: a) Ask for and get the cost of food. Use data type double. b) Ask for and get the tip percentage. Use data type double. c) Internally, declare the tax rate: const double tax_rate = 0.0825. Do not ask for tax rate. d) Compute the total bill: food cost * tax rate + tip. What should the tip be? Based on food cost? Food cost and tax? You decide; provide comments. e) Print out the total bill.

2) Body Mass Index (BMI) write code that computes BMI. The formula is: BMI = (weight in pounds / (height in inches x height in inches) ) x 703 a) Ask for and get the required data. Use data type int. b) Calculate the BMI. For the result, use data type double. c) Print out the BMI.

3) Combine the two parts above into a menu. Prompt the user for whether they want to perform: a) amount of bill; or b) BMI. a) Ask for and get the option desired. Use data type char. b) if option a, compute amount of restaurant bill; if option b, calculate BMI 4) Loop the program, Add option q to quit. Loop until the user enters q to quit. a) Enter a loop. a) Ask for and get the option desired. b) if option a, compute amount of restaurant bill; if option b, calculate BMI; if option q, quit

5)Following steps: a)

ignore the options case (uppercase or lowercase). Hint: use toupper() or tolower() b) format the output of the bill as: $xx.xx. format the BMI as xx.xx. (display 2 decimal places) c) display an error message if given an invalid option and continue the loop. d) ask for height in feet and inches instead of just inches; convert into inches. Example code for main loop:

while (true) { cout<<"Options: a)mount of restaurant bill; B)MI; q)uit: "; char option=' '; cin >> option; if (option=='a') { // compute and display the amount of the restaurant bill. } else if (option=='b') { // compute and display the BMI } else if (option=='q') break; else // invalid option entered, display an error message }

/* Example test output. This program computes amount of restaurant bill and / or BMI. Use q to quit. Options: a) mount of restaurant bill; B) MI; q) quit: a Food cost? 10 Tip rate? .1 Restaurant bill is: $11.82

Options: a)mount of restaurant bill; B)MI; q)uit: b Weight in pounds? 150 Height in inches? 72 BMI is: 20.34 Options: a)mount of restaurant bill; B)MI; q)uit: q Good-bye! *

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions