0

から関数を選択するのに問題がありますclass OperateClass

ユーザーに「足し算、引き算、掛け算、割り算のどれをしたいですか?私は:」(メイン)を尋ねます。私が何を入れても、それは関数に行きますint add。私は何が間違っているのですか?

#include <iostream>

using namespace std;

int x = 1;
int number;
int total = 0;
int amt = 1;
int a;
int b;
int c;
int d;
string ans;

class OperateClass{
    public:
        int add(){
            while(x <= 2){
                cout << "Enter a number to use to add: " << endl;
                    cin >> a;
                total = total + a;
                x++;
                amt++;
            }
        }

        int subtract(){
            while(x <= 2){
                cout << "Enter a number to use to add: " << endl;
                    cin >> b;
                total = total - b;
                x++;
                amt++;
            }
        }

        int multiply(){
            while(x <= 2){
                cout << "Enter a number to use to add: " << endl;
                    cin >> c;
                total = total * c;
                x++;
                amt++;
            }
        }

        int divide(){
            while(x <= 2){
                cout << "Enter a number to use to add: " << endl;
                    cin >> d;
                total = total / d;
                x++;
                amt++;
            }
        }
};

int main()
{

cout << "Do you want to add, subtract, multiply or divide? I want to : " << endl;
cin >> ans;

if(ans == "add"){
OperateClass opOper;
opOper.add();
    }

else if (ans == "subtract"){
    OperateClass opOper;
    opOper.subtract();
    }

else if (ans == "multiply"){
    OperateClass opOper;
    opOper.multiply();
    }

else if(ans == "divide"){
    OperateClass opOper;
    opOper.divide();

    }

}

また、この以下の関数は印刷するのに十分ですか?

void print(){
    cout << "Your total is: " << total << endl;  Where should I call this?

}
4

1 に答える 1

2

すべてのメソッドで同じテキストがあります"Enter a number to use to add: "

于 2012-07-17T02:52:05.127 に答える