永发信息网

C++的Calculator函数程序

答案:3  悬赏:10  手机版
解决时间 2021-03-23 01:38
  • 提问者网友:寂寞梧桐
  • 2021-03-22 07:09
C++的Calculator函数程序
最佳答案
  • 五星知识达人网友:人间朝暮
  • 2021-03-22 07:49
改后的:
#include
int add(int x, int y)
{ // add the numbrs x and y together and return the sum
std::cout << "Running calculator ...\n";
return (x+y);
}
int main()
{

std::cout <<"What is 867 + 5039?\n";
std::cout <<"the sum is " << add(867, 5309) << "\n\n";
std::cout <<"What is 777 + 9311?\n";
std::cout <<"the sum is " << add(777, 9311)<< "\n";
return 0;
}追问你这个成功了…能告诉我为什么和我的那个错在哪里吗? 我是按照书上输入的 错在什么地方我下次可以注意 谢谢!追答#include
int add(int x, int y)
{ // add the numbrs x and y together and return the sum
std::cout << "Running calculator ...\n";
//return (x+y) 少分号;
return (x+y);
}
int main()
{

std::cout <<"What is 867 + 5039?\n";
//std::cout <<"the sum is " << add(867 5309) << "\n\n"; 调用add函数参数间少逗号(英文的)
std::cout <<"the sum is " << add(867, 5309) << "\n\n";
std::cout <<"What is 777 + 9311?\n";
// 1.调用add函数参数间少逗号(英文的) 2.add (777 9311),add与(多了一个空格,3.转义字符换行是"\n",你这里写错了
//std::cout <<"the sum is " << add (777 9311)<< "/n";
std::cout <<"the sum is " << add(777, 9311)<< "\n";
return 0;
}
全部回答
  • 1楼网友:春色三分
  • 2021-03-22 08:54
return(x+y)的地方没有加分号追问加了也是错 而且 书上也没加追答肯定要加的,你把#include换成#include试试,而且那个add(867 5309)和add (777 9311)中间要加逗号追问
改了 但是还是不行 

是显示的这个
追答#include
int add(int x, int y)
{
// add the numbrs x and y together and return the sum
std::cout << "Running calculator ...\n";
return (x+y);
}
int main()
{
/* this program calls an add() function to add two different
sets of numbers together and display the results. the
add() function doesn't do anything unless it is called by
a line in the main() function.*/
std::cout <<"What is 867 + 5039?\n";
std::cout <<"the sum is " << add(867, 5309) << "\n\n";
std::cout <<"What is 777 + 9311?\n";
std::cout <<"the sum is " << add (777, 9311)<< "/n";
return 0;
}
  • 2楼网友:行雁书
  • 2021-03-22 08:47

return (x+y)后面少了分号;
std::cout <<"the sum is " << add(867 5309) << " ";//867 5309中间应该是逗号;
std::cout <<"the sum is " << add (777 9311)<< "/n";//867 5309中间应该是逗号。
以上改了相信就OK了……
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯