如何在C ++中停止我的命令行关闭

时间:2016-04-10 18:25:51

标签: c++ visual-c++

您好,我正在创建一个计算器,我的代码只是在这里继续跳到我的代码

// Calculator.cpp : Defines the entry point for the console application.//

#include "stdafx.h"
#include <cstdio>
#include <limits>
#include <iostream>


int num1, num2, ans, oper(0);



int main()
{
    std::cout << "Put in your first number to be calculated" <<std::endl;
    std::cin >> num1;
    std::cout << "Put in your second number to be calculated"<<std::endl;
    std::cin >> num2;
    std::cout << "The next bit is abit complicated, blame the code writer for that he cant use char yet but anyway." << std::endl;
std::cout << "If you want multiplication press 1 then enter." << std::endl;
std::cout << "If you want division prees 2 then enter." << std::endl;
std::cout << "If you want addition press 3 then enter." << std::endl;
std::cout << "If you want subtraction press 4 then enter." << std::endl;
std::cin.get();
if (oper == 1) {
    ans = num1*num2;
    std::cout << ans;
}
while (oper == 2) {
    ans = num1 / num2;
    std::cin.get();
    std::cout << ans;
    std::cin.get();
}
while (oper == 3) {
    ans = num1 + num2;
    std::cout << ans;
    std::cin.get();
}
    while (oper == 4) {
        ans = num1 - num2;
        std::cout << ans;
        std::cin.get();
        }
return 0;
}

我正在为此寻找解决方案,任何人都可以帮助我,如果这是一个简单的问题,我很抱歉,我是C ++新手

0 个答案:

没有答案