多个int main()的?

-5 c++

我刚开始学习c ++,我试图让自己接受简单的加法和减法.但是我似乎无法运行此功能.任何输入都将得到很好的赞赏.我也接受建设性的批评:)

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

int main()
{
    std::cout << " I have a qustion for you Devante. Here it is . . . if you add the word two to the number 2, what do you get ?";
    int x = 4;
    std::cin >> x;
    std::cout << "Correct, the correct answer is " << x << std::endl;
    return 0;
}

int main()
{   
    std::cout << " Since you got the answer right this time, lets see if you can subtract. What is 6 - 6 ? ";
    int x = 0;
    std::cin >> x;
    std::cout << "Correct, the answer is " << x << std::endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

R S*_*ahu 7

您只能main在程序中使用一个功能.

你能做的是......

将代码放在两个不同命名的函数中.
打电话给他们main.

int test1()
{
    std::cout << " I have a qustion for you Devante. Here it is . . . if you add the word two to the number 2, what do you get ?";
    int x = 4;
    std::cin >> x;
    std::cout << "Correct, the correct answer is " << x << std::endl;
    return 0;
}

int test2()
{   
    std::cout << " Since you got the answer right this time, lets see if you can subtract. What is 6 - 6 ? ";
    int x = 0;
    std::cin >> x;
    std::cout << "Correct, the answer is " << x << std::endl;
    return 0;
}

int main()
{
   test1();
   test2();
   return 0;
}
Run Code Online (Sandbox Code Playgroud)