したがって、私が抱えている問題は、プログラムを実行すると最初の入力を求められるが、オペレーターに入力した後、出力画面が停止し、出力画面を強制終了する必要があることです。while ループを使用して、ユーザーが必要な数の数字を入力できるようにしています。ユーザーが = 記号を入力すると、プログラムを終了して出力を出力する必要があります。
// C++ program to develop a simple text based calculator where you can do addition, subtraction, multiplication and division.
#include <iostream>
using namespace std;
class calci
{
private:
char op; // variable for the operator
double no; // variable for getting input numbers
double out; // for the output
public:
void input(char ,double,double); //to accept input values as well as calculate the output
void output(); //to print the output
};
void calci :: input(char op,double no,double out)
{ op= '+'; //given as a default value for op so that the while loop can start
while(op != '=') // Used just to make the user input as many numbers as they want untill they give a '=' sign
{
std::cout <<"Enter the first number:"<<endl;
std::cin >>no;
std::cout <<"\nEnter the operation to be performed with this number";
std::cout <<"\nEnter + for Additon \nEnter - for Subtraction \nEnter * for multiplication \nEnter / for division \nEnter = to produce the output"<<endl;
std::cin >>op;
while(op != '=')
{
switch(op)
{
case '+' :
out=out+no;
break;
case '-' :
out=out-no;
break;
case '*':
out=out*no;
break;
case '/':
out=out/no;
break;
default:
break;
}
}
}
}
void calci :: output()
{
cout<<"the final answer is"<<out;
}
int main()
{
calci c;
std::cout << "Hello!"<<endl;
c.input('+',2.0,2.0);
c.output();
return 0;
}