Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program, which will act as a simple four - function calculator. That is it will read a number, read an operator, read another

Write a program, which will act as a simple four

-

function calculator. That is it will read a

number, read an operator, read another number, then

do the operation. The calculator

works with integers and uses four functions: +,

-

, *, and /. After the first operation is

completed, the program will read another operator and uses the result of the previous

operation as the first value for the next oper

ation. If the user enters a C the result is

cleared and then the user starts entering a new number. If the user enters an X, the

calculator is turned off. The various input values (i.e. numbers, operators, commands)

will be followed by the ENTER key. Your

program should prompt the user on what the

user is to do. The commands C and X may be entered in place of an operator.

All numbers entered and displayed will be integer values.

so, this is my code

#include

using namespace std;

#include

void main()

{

int num1, num2;

int answer;

char Oper;

bool ValidOp;

F:

num1=0;

num2=0;

answer=0;

cout<<"Enter the first number."<

cin>>num1;

do {

O:

cout<<"Enter a vaild operater.";

cin>>Oper;

ValidOp = false;

cout<<"Enter the second number.";

cin>>num2;

switch (Oper)

{

case '+':

answer= num1+num2;

break;

case '-':

answer= num1-num2;

break;

case '*':

answer= num1*num2;

break;

case '/':

answer= num1/num2;

break;

case 'c':

case 'C':

ValidOp = false;

cout<<"Answer is cleared"<

goto F;

break;

case 'x':

case 'X':

ValidOp = false;

cout<<"Calculator is turned off"<

exit (0);

break;

default:

ValidOp = false;

cout<<"You entered invalid operater. Plese enter a valid operater"<

goto O;

break;

}

cout<<"The answer is= "<

}while(!ValidOp);

}

but it keeps saying fatal error when I do debugging

I don't know why

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

Students also viewed these Databases questions

Question

2. In what way can we say that method affects the result we get?

Answered: 1 week ago