cin命令用于在函数上插入值 [英] cin command to use for inserting value on a function
本文介绍了cin命令用于在函数上插入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 cin
插入该函数的值?
How could I use cin
to insert values for the function?
cin >> addNumber();
cout << addNumber() << endl;
我不确定我是否正确使用了以上这些行.我应该使用什么命令/单词或它叫什么来做到这一点?我正在尝试为变量 x
和 y
添加一个值,以将这两个数字相加并打印总和.
I am not sure if I used these lines above properly.
What command/word or whatever it is called should I use to be able to do so? I'm trying to add a value for the variables x
and y
to add those two numbers and print the sum.
#include <iostream>
using namespace std;
int addNumber(int x, int y)
{
int answer = x + y;
return answer;
}
int main()
{
cin >> addNumber();
cout << addNumber() << endl;
return 0;
}
推荐答案
#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;
}
这篇关于cin命令用于在函数上插入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文