C++中的程序为什么提示调用参数过多?
#include"stdafx.h"#include<iostream>#include<iomanip>#include<cmath>usingnamespacestd...
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const double PI=3.141593;
void area() {
double a;
double s;
s = PI * a * a;
}
void area() {
double a;
double b;
double c;
double s;
double d;
d = (a+b+c) / 2.0;
s = sqrt(d*(d-a)*(d-b)*(d-c)) ;
}
void area() {
double a;
double b;
double s;
s = a * b;
}
void showmenu()
{
cout<<"choice a:circle"<<endl;
cout<<"choice b:triangle"<<endl;
cout<<"choice c:rectangle"<<endl;
cout<<"input your choice:"<<endl;
}
int main()
{
int a,b,c;
char choice;
double s;
showmenu();
cin>>choice;
while (choice!='0')
{switch (choice)
{case 'a':cout<<"输入半径:"<<endl;
cin>>a;
area(a,b,c,s);//提示调用参数太多
break;
case 'b':cout<<"输入底边长和高:"<<endl;
cin>>a>>b>>c;
area(a,b,s);//也有提示
break;
case 'c':cout<<"输入长、宽:"<<endl;
cin>>a>>b;
area(a,s);//同上也提示
}
cout<<"area="<<s<<endl;
showmenu();
cin>>choice;
}
return 0;
} 展开
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const double PI=3.141593;
void area() {
double a;
double s;
s = PI * a * a;
}
void area() {
double a;
double b;
double c;
double s;
double d;
d = (a+b+c) / 2.0;
s = sqrt(d*(d-a)*(d-b)*(d-c)) ;
}
void area() {
double a;
double b;
double s;
s = a * b;
}
void showmenu()
{
cout<<"choice a:circle"<<endl;
cout<<"choice b:triangle"<<endl;
cout<<"choice c:rectangle"<<endl;
cout<<"input your choice:"<<endl;
}
int main()
{
int a,b,c;
char choice;
double s;
showmenu();
cin>>choice;
while (choice!='0')
{switch (choice)
{case 'a':cout<<"输入半径:"<<endl;
cin>>a;
area(a,b,c,s);//提示调用参数太多
break;
case 'b':cout<<"输入底边长和高:"<<endl;
cin>>a>>b>>c;
area(a,b,s);//也有提示
break;
case 'c':cout<<"输入长、宽:"<<endl;
cin>>a>>b;
area(a,s);//同上也提示
}
cout<<"area="<<s<<endl;
showmenu();
cin>>choice;
}
return 0;
} 展开
3个回答
展开全部
你的每个area()函数里都没有参数所以你怎么传递参数进这个函数?怎么进行重载呢?
比如第一个函数有一个参数:注意箭头的地方 函数体内 去掉double a 而且你这里有个问题,s是在函数体内定义的变量,在执行完这个函数以后s会被销毁,这样你并不能得到正确的s的值
↓
void area(double a) {
double s;
s = PI * a * a;
}
其他的道理一样
比如第一个函数有一个参数:注意箭头的地方 函数体内 去掉double a 而且你这里有个问题,s是在函数体内定义的变量,在执行完这个函数以后s会被销毁,这样你并不能得到正确的s的值
↓
void area(double a) {
double s;
s = PI * a * a;
}
其他的道理一样
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const double PI=3.141593;
void area(const double &a,double &s) {
s = PI * a * a;
}
void area(const double &a,const double &b,const double &c,double &s)
{
double tempd = (a+b+c) / 2.0;
s = sqrt(tempd*(tempd-a)*(tempd-b)*(tempd-c)) ;
}
void area(const double &a,const double &b,double &s) {
s = a * b;
}
void showmenu()
{
cout<<"choice a:circle"<<endl;
cout<<"choice b:triangle"<<endl;
cout<<"choice c:rectangle"<<endl;
cout<<"input your choice:"<<endl;
}
int main()
{
int a,b,c;
char choice;
double s;
showmenu();
cin>>choice;
while (choice!='0')
{
switch (choice)
{
case 'a':cout<<"输入半径:"<<endl;
cin>>a;
area(a,s);//提示调用参数太多
break;
case 'b':cout<<"输入三角形边长:"<<endl;
cin>>a>>b>>c;
area(a,b,c,s);//也有提示
break;
case 'c':cout<<"输入长、宽:"<<endl;
cin>>a>>b;
area(a,b,s);//同上也提示
}
cout<<"area="<<s<<endl;
showmenu();
cin>>choice;
}
return 0;
}
修改了一下,测试可以了!
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const double PI=3.141593;
void area(const double &a,double &s) {
s = PI * a * a;
}
void area(const double &a,const double &b,const double &c,double &s)
{
double tempd = (a+b+c) / 2.0;
s = sqrt(tempd*(tempd-a)*(tempd-b)*(tempd-c)) ;
}
void area(const double &a,const double &b,double &s) {
s = a * b;
}
void showmenu()
{
cout<<"choice a:circle"<<endl;
cout<<"choice b:triangle"<<endl;
cout<<"choice c:rectangle"<<endl;
cout<<"input your choice:"<<endl;
}
int main()
{
int a,b,c;
char choice;
double s;
showmenu();
cin>>choice;
while (choice!='0')
{
switch (choice)
{
case 'a':cout<<"输入半径:"<<endl;
cin>>a;
area(a,s);//提示调用参数太多
break;
case 'b':cout<<"输入三角形边长:"<<endl;
cin>>a>>b>>c;
area(a,b,c,s);//也有提示
break;
case 'c':cout<<"输入长、宽:"<<endl;
cin>>a>>b;
area(a,b,s);//同上也提示
}
cout<<"area="<<s<<endl;
showmenu();
cin>>choice;
}
return 0;
}
修改了一下,测试可以了!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
area()没有参数, 你怎么传进去?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询