Question
develop an algorithm which includes input, process, and output sections #include #include using namespace std; int main() { int choice; //assign a boolean value true
develop an algorithm which includes input, process, and output sections
#include
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started