需要帮助 - 启动功能 [英] Need help -- starting functions

查看:65
本文介绍了需要帮助 - 启动功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include< iostream>

#include< cmath>

using namespace std;

int water_bill(int usage_in_cubic_meters);


int main()

{

cout<< 输入以立方米为单位的使用量:;

返回0;

}


int water_bill(int usage_in_cubic_meters)

{


cin>> usage_in_cubic_meters;


if(usage_in_cubic_meters< = 0)

cout<< 错误:请输入一个大于0的数字。;


else if(usage_in_cubic_meters< = 1000)

cout<< 你的账单是:15美元;


否则如果(usage_in_cubic_meters> 3000)

cout<< 你的账单是70美元;


返回usage_in_cubic_meters;


}


如何来吧,这不会进入water_bill功能,只是在主要功能后停止

停止?

#include <iostream>
#include <cmath>
using namespace std;
int water_bill(int usage_in_cubic_meters);

int main()
{
cout << "Enter the amount of usage in cubic meters: ";
return 0;
}

int water_bill(int usage_in_cubic_meters)
{

cin >> usage_in_cubic_meters;

if (usage_in_cubic_meters <= 0)
cout << "ERROR: please enter a number above 0.";

else if (usage_in_cubic_meters <= 1000)
cout << "Your bill is: $15";

else if (usage_in_cubic_meters > 3000)
cout << "Your bill is $70";

return usage_in_cubic_meters;

}

how come this wont go into the water_bill function and it just keeps
stopping after the main function?

推荐答案

15"


else if(usage_in_cubic_meters> 3000)

cout<< 你的账单是
15";

else if (usage_in_cubic_meters > 3000)
cout << "Your bill is


70" ;;


返回usage_in_cubic_meters;


}


为什么这不会进入water_bill功能,它只是保持

在主要功能之后停止?

70";

return usage_in_cubic_meters;

}

how come this wont go into the water_bill function and it just keeps
stopping after the main function?


我认为你习惯使用脚本语言,或者来吧。
$ C $ b in C ++所有执行的代码都是main()内部的内容

函数(以及它调用的函数)。

因此,如果你想运行water_bill代码,你需要在main中调用它。

。下面的代码应该是你要找的。


int main()

{

cout<< 输入以立方米为单位的使用量:;

int usage_in_cubic_meters;

cin>> usage_in_cubic_meters;

water_bill(usage_in_cubic_meters);

返回0;

}

i think you are used to work with script languages, or comething.
in C++ ALL the code that is executed is what is inside the main()
function (and the functions that it calls).
So, if you want the water_bill code to run you need to put a call to it
inside the main. The code bellow should be what you are looking for.

int main()
{
cout << "Enter the amount of usage in cubic meters: ";
int usage_in_cubic_meters;
cin >> usage_in_cubic_meters;
water_bill(usage_in_cubic_meters);
return 0;
}


这篇关于需要帮助 - 启动功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆