CornIT 2020-03-08 15:33 采纳率: 0%
浏览 250
已采纳

请问大佬们,C++出现函数嵌套问题怎么处理

要求做一个计算ax^2+bx+c=0的程序,程序做出来可以运行,但是我设计的报错环节总有问题,报完错下面的过程仍会照常输出,我希望它报完错就停止运行。老师给我的解释是出现了函数嵌套的问题,但是初学我看不出问题,请
大佬指教。

#include
#include
using namespace std;
void caluate();
int main(){
double a,b,c;
cout<<"calcuate ax^2+bx+c=0"< cout>a;
cout<<"the number of 'b' is"<>b;
cout<<"the number of 'c' is"<>c;
double x,y,z,h,l,m;
m=b*b-4*a*c;
if(m<0) cout<<"This question unanswered !"<<endl;
else void calcuate();

void calcuate();
{
x=sqrt(m); /*计算更号下b^2-4ac*/
y=(-b+x); z=(-b-x); /*计算步骤*/
h=y/2*a; l=z/2*a;
cout<<"The result is:"<<endl;
cout<<"X1= "<<h<<endl;
cout<<"X2= "<<l<<endl;
}
system("pause");
return 0;
}

  • 写回答

1条回答 默认 最新

  • threenewbee 2020-03-08 16:19
    关注

    虽然用函数多此一举,但是你非要用得这么写

    问题解决的话,请点下采纳

    #include <iostream>
    #include <stdlib.h>
    #include <math.h>
    using namespace std;
    
    void calcuate(double a, double b, double c, double x, double y, double z, double h, double l, double m);
    
    int main(){
        double a,b,c;
        cout<<"calcuate ax^2+bx+c=0"<< endl;
        cin>>a;
        cout<<"the number of 'b' is"<< endl;
        cin>>b;
        cout<<"the number of 'c' is"<< endl;
        cin>>c;
        double x,y,z,h,l,m;
        m=b*b-4*a*c;
        if(m<0) cout<<"This question unanswered !"<<endl;
        else calcuate(a,b,c,x,y,z,h,l,m);
        system("pause");
        return 0;
    }
    void calcuate(double a, double b, double c, double x, double y, double z, double h, double l, double m)
    {
        x=sqrt(m); /*计算根号下b^2-4ac*/
        y=(-b+x); z=(-b-x); /*计算步骤*/
        h=y/2*a; l=z/2*a;
        cout<<"The result is:"<<endl;
        cout<<"X1= "<<h<<endl;
        cout<<"X2= "<<l<<endl;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测