Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For my C++ lab i have to create a program to use If statements and loops. ive attached the procedure down below as well as

For my C++ lab i have to create a program to use If statements and loops. ive attached the procedure down below as well as the code ive made so far. im working on this in visual studio if that makes a diffrence and only includes that can be used are the ones ive placed in my code. there is an error in my code for my 'type' term as i havent initalized it, im having trouble understanding what that means.

the code:

#include #include #include

#define _CRT_SECURE_NO_WARNINGS /******************************************************************************* LAB 4: If statements ******************************************************************************** Developed by: Date: Jan 31, 2020 ******************************************************************************** Description: Using if statements *******************************************************************************/

/******************************************************************************* Main *******************************************************************************/ void purpose(); float getNumber(float);

void main() { //Variable Declarations/user inputs purpose(); //print the message char type; // for metric or imperial (MPG or L/100km)

while ((((type != 'l') || (type != 'L') || (type != 'M') || (type != 'm')))) { char type; printf("Please enter L or l for MPG to L/100km or"); printf(" enter M or m for L/100km to MPG "); fflush(stdin); type = getchar();

if (type == 'L' || type == 'l') { printf("you have chosen to convert MPG to L/100km "); fflush(stdin); } else { if (type == 'M' || type == 'm') { printf(" you have chosen to convert L/100km to MPG "); fflush(stdin); }

if (type != 'm' || type != 'M' || type != 'l' || type != 'L') { printf("SORRY BUT THAT WAS NOT ONE OF THE OPTIONS"); printf(" YOU ARE AN IDIOT "); } }

} while (!_kbhit()); }

/******************************************************************************* Purpose - This function prints the purpose of the program to the console.

Inputs: none

Returned: none *******************************************************************************/

void purpose() { printf(" This program will convert MPG to L/100km OR L/100km to MPG "); printf(" depending on the users choice ");

} image text in transcribed

image text in transcribed

continuing from the code ive placed please follow the procedure below. making a program that explains the purpose in a function, then asking the user to either enter m or l for metric or imperial. if they choose a diffrent answer it will bring up an error message and ask again. then itll do the calculations. the entire procedure is at the bottom of the question that says exactly what needs to be done.
Explain the purpose of the program to the user. Do this in a separate function. Request the type of conversion: MPG to L/100km (accept only L or I) or L/100km to MPG (accept M or m only). Continue to ask the user until the correct selection is made. Do this in main. Request the rate (accept 10-60 MPG inclusive only) and (accept 3-30 1/100km inclusive only). Continue to ask the user until the rate is within th specified range. Do this in a separate function. Do the conversion. Use imperial gallons (4.546 liters per gallon) in your calculations. Do this in a separate function, the function must be called from main. Display the result. The output should include the input rate including units and the converted rate including units. The output must be displayed with an accuracy of two decimal places. Do this in a separate function. Ask the user if he/she would like to complete another conversion. If so (accept Y or y only), do not explain the purpose of the program again. The program should continue until the user would like to quit. Do this in main

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

Visual Basic 4 Ole Database And Controls Superbible

Authors: Michael Hatmaker, C. Woody Butler, Ibrahim Malluf, Bill Potter

1st Edition

1571690077, 978-1571690074

More Books

Students also viewed these Databases questions

Question

What is a price variance? What is a quantity variance?

Answered: 1 week ago