help needed

(Write a program that will get two numbers from the user and then ask them if they would like to add, subtract, multiply, or divide the two numbers. The program should repeat until the user wants to exit.)

Rewrite the calculate program using the attached pseudocode and prototypes.

Step 1: Create stub functions based on the prototypes given and a running shell program demonstrating that the function prototypes and headings are properly constructed.

Step 2: Write the actual code for the functions. (The more functions completed, the more points gained for the assignment.)
Submit:

Source code for shell program from Step 1
Source code for final program from Step 2
1
2
Source code for shell program from Step 1
Source code for final program from Step 2

What is the source code given for the assignment?
#include <iostream>

using namespace std;

int main()
{
// Variables
float num1, num2, result;
char operation; // Holds operation entered by user
char answer = 'Y'; // Holds loop continuation value entered by user

while (answer == 'Y'){
// Prompt user for two numbers
cout << "Enter two numbers: ";
cin >> num1 >> num2;

while (!cin){
cout << "Invalid number!" << endl;
cin.clear();
cin.ignore(100, '\n');

cout << "Enter two numbers: ";
cin >> num1 >> num2;
}

// Prompt user for operation
cout << "Enter operation (a)dd, (s)ubtract, (m)ultiply, (d)ivide: ";
cin >> operation;

// Based on operation entered, perform calculation
switch (operation) {
case 'a':
case 'A':
result = num1 + num2;
break;
case 's':
case 'S':
result = num1 - num2;
break;
case 'd':
case 'D':
if (num2 == 0) {
cout << "Cannot divide by 0!" << endl;
return 0;
}
result = num1 / num2;
break;
case 'm':
case 'M':
result = num1 * num2;
break;
default:
cout << "Invalid operation!!!" << endl;
return 1;
}

// Output result
cout << "Result: " << result << endl << endl;

do {

cout << "Do you want to continue? (y/n) ";
cin >> answer;
cin.ignore(100, '\n');
answer = toupper(answer);

} while ((answer != 'Y') && (answer != 'N'));

}

return 0;
}




Above is a source code I guess
Topic archived. No new replies allowed.