Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// Need my program to loop until user wants to stop. This is what I have so far.

ID: 3533863 • Letter: #

Question

// Need my program to loop until user wants to stop. This is what I have so far.
#include <iostream> using namespace std;
// input function void Input (float &x, float &y);
float a=1.0, b=1.0, result; char operation;

int main () { cout << "Program that performs addition, subtraction, multiplication and subtraction. "; cout << "Please input first number;" << endl; cin >> a; cout << "Please enter operator :" <<endl; cin>> operation; cout << "Please enter second number;" << endl; cin >> b; Input (a,b);
cout << "The answer is: " << result << endl;
return 0; }

void Input (float &x, float &y) { a = x; b = y;
switch (operation) { if ( operation == '+' || operation == '-' || operation == '*' || operation == 'Q' || operation == 'q') case '+': result = x + y; break;
case '-': result = x - y; break;
case '*': result = x * y; break;
case '/': result = x / y; break; case 'q': case 'Q': break; default:
cout << "Invalid operation. Please input a correct calculation operation: "; cin >> a >> operation >> b; Input (a, b); } { if ( !operation == '+' || !operation == '-' || !operation == '*' || !operation == 'Q' || !operation == 'q')
cout << "Invalid operation. Please input a correct calculation operation: "; cin >> a >> operation >> b; Input (a, b); } } // Need my program to loop until user wants to stop. This is what I have so far.
#include <iostream> using namespace std;
// input function void Input (float &x, float &y);
float a=1.0, b=1.0, result; char operation;

int main () { cout << "Program that performs addition, subtraction, multiplication and subtraction. "; cout << "Please input first number;" << endl; cin >> a; cout << "Please enter operator :" <<endl; cin>> operation; cout << "Please enter second number;" << endl; cin >> b; Input (a,b);
cout << "The answer is: " << result << endl;
return 0; }

void Input (float &x, float &y) { a = x; b = y;
switch (operation) { if ( operation == '+' || operation == '-' || operation == '*' || operation == 'Q' || operation == 'q') case '+': result = x + y; break;
case '-': result = x - y; break;
case '*': result = x * y; break;
case '/': result = x / y; break; case 'q': case 'Q': break; default:
cout << "Invalid operation. Please input a correct calculation operation: "; cin >> a >> operation >> b; Input (a, b); } { if ( !operation == '+' || !operation == '-' || !operation == '*' || !operation == 'Q' || !operation == 'q')
cout << "Invalid operation. Please input a correct calculation operation: "; cin >> a >> operation >> b; Input (a, b); } }

Explanation / Answer

#include <iostream>

using namespace std;


// input function

void Input (float &x, float &y);


float a=1.0, b=1.0, result;

char operation;



int main ()

{

cout << "Program that performs addition, subtraction, multiplication and subtraction. ";

while(1)

{

cout << "Press -1 to exit or 1 continue;" << endl;

int in;

cin >> in;

if(in == -1)

{

cout << "goodbye" << endl;

return 0;

}

cout << "Please input first number;" << endl;

cin >> a;

cout << "Please enter operator :" <<endl;

cin>> operation;

cout << "Please enter second number;" << endl;

cin >> b;

Input (a,b);


cout << "The answer is: " << result << endl;

}

return 0;

}



void Input (float &x, float &y)

{

a = x;

b = y;


switch (operation)

{ if ( operation == '+' || operation == '-' || operation == '*' || operation == 'Q' || operation == 'q')

case '+':

result = x + y;

break;


case '-':

result = x - y;

break;


case '*':

result = x * y;

break;


case '/':

result = x / y;

break;

case 'q':

case 'Q':

break;

default:


cout << "Invalid operation. Please input a correct calculation operation: ";

cin >> a >> operation >> b;

Input (a, b);

}

{ if ( !operation == '+' || !operation == '-' || !operation == '*' || !operation == 'Q' || !operation == 'q')


cout << "Invalid operation. Please input a correct calculation operation: ";

cin >> a >> operation >> b;

Input (a, b);

}

}