cin command to use for inserting value on a function

后端 未结 2 1324
难免孤独
难免孤独 2021-01-28 07:19

How could I use cin to insert values for the function?

cin >> addNumber();
cout << addNumber() << endl;

I am not

相关标签:
2条回答
  • 2021-01-28 08:19
    #include <iostream>
    
    using namespace std;
    
    int addNumber(int x, int y)
    {
        int answer = x + y;
        return answer;
    }
    
    int main()
    {   
        int x,y;
        cout<<"Enter first number"<<endl;
        cin>>x;
        cout<<"Enter second number"<<endl;
        cin>>y;    
        cout<<addNumber(x,y)<<endl;
        return 0;
    }
    
    0 讨论(0)
  • 2021-01-28 08:21
    #include <iostream>
    
    int addNumber(int x, int y)
    {
        int answer = x + y;
        return answer;
    }
    
    int main()
    {
        int x,y;
        std::cin >> x >> y;
    
        std::cout << addNumber(x,y) << std::endl;
    
        return 0;
    }
    
    0 讨论(0)
提交回复
热议问题