Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop an algorithm for the program which includes input, process, and output sections. Format: 1.) Input 2.) Process 3.) Output CODE: #include #include using namespace

Develop an algorithm for the program which includes input, process, and output sections.

Format:

1.) Input

2.) Process

3.) Output

CODE:

#include #include using namespace std;

int main() { int choice; //assign a boolean value true bool run=true; double starttemp, endtemp, temp_incr, temp_conv;

cout << "Choose a conversion type: " << endl; cout << " 1. Convert F to C" << endl; cout << " 2. Convert C to F" << endl; cout << " 3. Quit" << endl; cout << "What is your choice? "; cin >> choice;

// Verify input is a number within the correct range if (!cin || choice < 1 || choice > 3) { cout << "Invalid choice. Try again." << endl; return 0; } else if (choice == 3) { cout << "Thank you for using my program. Program terminated." << endl; return 0; }

cout << "Enter starting value: "; cin >> starttemp; cout << "Enter ending value: "; cin >> endtemp; cout << "Enter increment value: "; cin >> temp_incr;

// Verify input is a number if (!cin) { cout << "Invalid data type, must be a number. Program terminated." << endl; return 0; }

// Print table header if (choice == 1) { cout <<"Fahrenheit" << setw(20) << "Celsius" << endl; } else { cout << "Celsius" << setw(20) << "Fahrenheit" << endl; } // Print table rows if(choice==1) { while(starttemp>=endtemp) { //set to run to false run=false; temp_conv = (5.0/9.0)*(starttemp - 32.0); cout << fixed << setprecision(2) << starttemp << setw(20) << temp_conv << endl; starttemp=starttemp+temp_incr; } //run the below loop only if run is true while(starttemp<=endtemp && run==true) { temp_conv = (5.0/9.0)*(starttemp - 32.0); cout << fixed << setprecision(2) << starttemp << setw(20) << temp_conv << endl; starttemp=starttemp+temp_incr; } } else { while(starttemp>=endtemp) { //set to run to false run=false; temp_conv = (9.0/5.0)*starttemp + 32.0; cout << fixed << setprecision(2) << starttemp << setw(20) << temp_conv << endl; starttemp=starttemp+temp_incr; } //run the below loop only if run is true while(starttemp<=endtemp && run==true) { temp_conv = (9.0/5.0)*starttemp + 32.0; cout << fixed << setprecision(2) << starttemp << setw(20) << temp_conv << endl; starttemp=starttemp+temp_incr; } }

return 0; }

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

Deductive And Object Oriented Databases Second International Conference Dood 91 Munich Germany December 18 1991 Proceedings Lncs 566

Authors: Claude Delobel ,Michael Kifer ,Yoshifumi Masunaga

1st Edition

3540550151, 978-3540550150

More Books

Students also viewed these Databases questions