【发布时间】:2015-05-16 04:00:11
【问题描述】:
我需要有关修复程序的帮助。它没有运行。我不断收到警告控制到达非 void 函数的结尾。我不知道如何解决它。请帮我。该程序假设找到球体的体积或表面积。我在最后 2 个收到警告 }
#include <iostream>
#include <iomanip>
#include <cmath>
#include <math.h>
using namespace std;
char s = '\0';
const char SENTINEL = 's';
float radius, answer;
void get_radius (float&);
float surface_area (float);
float volume (float);
float cross_section (float);
const float PI = 3.14;
int main()
{
cout << "This program will let you input the radius of a sphere to find its volume or surface area." << endl << endl;
cout << "Enter 'v' for volume or 'a' for surface area of a sphere" << endl;
cout << "'s' to stop" << endl;
cin >> s;
while (s != SENTINEL)
{
get_radius (radius);
if(s == 'V')
{
volume (radius);
}
else if(s == 'A')
{
surface_area (radius);
}
cout << "Enter 'v' for volume or 'a' for surface area of a sphere" << endl;
cout << "'s' to stop" << endl;
cin >> s;
}
system("PAUSE");
return 0;
}
void get_radius (float& radius)
{
cout << "Please enter the radius of the sphere: " << endl;
cin >> radius;
}
float volume (float radius){
float answer;
answer = 4.0/3.0 * PI * pow (radius, 3);
cout << "The volume is: " << answer << endl;
}
float surface_area (float radius){
float answer;
answer = 4.0 * PI * pow(radius, 2);
cout << "The surface area is: " << answer << endl;
}
【问题讨论】:
-
volume()和surface_area()return都没有。 -
那我该如何解决。我试过 return 0;但它不起作用
-
当你编写代码时,先从一些小而简单的东西开始,然后逐步构建。如果你这样做了,你就会确切地知道问题出在哪里,并且快速浏览一下教科书就会告诉你如何编写一个返回一些东西的函数。
标签: c++