Question: develop an algorithm and make it into a code block right at the very beginning (before code) Verify that code follows best programming principles, including

develop an algorithm and make it into a code block right at the very beginning (before code)

Verify that code follows best programming principles, including the design and thoroughness of the algorithm, descriptive variable names, the use of appropriate data types, and code that is easy to read.

#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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!