当前位置:编程学习 > C/C++ >>

C++代码的问题

#include <iostream.h>
#include <stdio.h>
double circle_1(double square,double b,double pai(3.14))
{
 square=pai * b * b;
 return square;
}
double rectangle_1(double a,double b,double square)
{
 square=a*b;
 return square;
}
double Square_1(double a,double square)
{
 square=a*a;
 return square;
}
void main()
{  char s[5];
 double b;
 double a;
 double z;
 double k;
 cout<<"请输入你要算面积的图形:";
 cin>>char s[9];
 if(char s[9]="圆形")
 cout<<"请输入圆的半径:";
 cin>>b;
    double circle_1(double square,double b,double pai(3.14))
 cout<<"圆的面积="<<circle_1(a,b,s)<<endl;

 if(char s[9]="长方形")
 cout<<"请输入长方形的长和宽:";
 cin>>a>>k;
 double rectangle_1(double a,double k,double square)
 cout<<"长方形的面积="<< rectangle_1(double a,double b,double square)<<endl;
 if(char s[9]="正方形")
 cout<<"请输入正方形的边长:";
 cin>>z;
 double Square_1(double z,double square)
 cout<<"正方形的面积="<<Square_1(double z,double square)<<endl;

 
请高手帮我改改这个程序。急

追问:

呵呵,我是自学的。正在努力中.....

答案:#include <iostream.h>
#include <stdio.h>
#include "string.h"
const double pai=3.14;
double circle_1(double r)
{
    return pai*r*r;
}
double rectangle_1(double a,double b)
{
    return a*b;
}
double Square_1(double a)
{
    return a*a;
}
int  main()
{  
    char s[5];
    double b;
    double a;
    while(1)
    {
        cout<<"请输入你要算面积的图形:";
        cin>>s;
        if(!strcmp(s,"圆形"))
        {
            cout<<"请输入圆的半径:";
            cin>>b;
            cout<<"圆的面积="<<circle_1(b)<<endl;
        }
        
        else if(!strcmp(s,"长方形"))
        {
            cout<<"请输入长方形的长和宽:";
            cin>>a>>b;
            cout<<"长方形的面积="<< rectangle_1(a,b)<<endl;
        }
        else if(!strcmp(s,"正方形"))
        {
            cout<<"请输入正方形的边长:";
            cin>>b;
            cout<<"正方形的面积="<<Square_1(b)<<endl;
        }
        else
        {
            cout<<"输入错误"<<endl;
        }
        cout<<"重新选择"<<endl;
    }
    return 0;
}


兄弟不论你的C++和谁学得,我严重建议你换一个老师

上一个:ajax中的对象?
下一个:零基础学Java Web开发:JSP+Servlet+Struts+Spring+Hibernate+Ajax(第2版)

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,