- 分享
- 0
- 人气
- 0
- 主题
- 5
- 帖子
- 1478
- UID
- 190660
- 积分
- 584
- 阅读权限
- 17
- 注册时间
- 2009-1-5
- 最后登录
- 2015-12-24
- 在线时间
- 3650 小时
|
回复 7# god_of_war
首先告诉你哪里 Salah :- #include <stdio.h>
- #include <math.h>
- #include <windows.h>
- void calsquare(void);
- void calcone(void);
- void calcircle(void);
- int main()
- {
- char y; //这里错, y 的 data type 必须是 int, 因为你的 Selection 是写 1 / 2 / 3 / 4 的.. 如果 char 的话是 a b c..
- printf("Menu\n");
- printf("1. Find Area and Perimeter of Square\n");
- printf("2. Find Area and Perimeter of Cone\n");
- printf("3. Find Area and Perimeter of a Circle\n");
- printf("4. Quit\n");
- printf("Input the following function\n");
- scanf("%s", &y); //这里错, %d 才对, 因为读取的是 integer / digit
- switch(y)
- {
- case “1”: //这里错, case 1: 就可以了, 并不用放任何符号, 而且你的符号也是错的, 你这边用的符号是华文输入法的开关引号 ..
- calsquare()(); //这里错, 怎么两个 () () ~
- break;
- case “2”: //这里错, 同上
- calcone();
- break;
- case “3”: //这里错, 同上
- calcircle();
- break;
- case “4”: //这里错, 同上
- system("EXIT");
- break; //可有可无
- }
- }
- void calsquare(void)
- {
- float area = 0;
- float perimeter = 0;
- float x = 0;
- system("CLS");
- printf("Input the side of x : ");
- scanf("%f", &x);
- area = (x*x);
- perimeter = (4*x);
- printf("Area of square = %.2f\n", area);
- printf("Perimeter of square = %.2f\n", perimeter);
- //getch();
- }
- void calcone(void)
- {
- float area = 0;
- float volume = 0;
- float s = 0, r = 0, h = 0;
- system("CLS");
- printf("Input the side of s : ");
- scanf("%f", &s);
- printf("Input the side of r : ");
- scanf("%f", &r);
- printf("input the side of h");
- scanf("%f", &h);
- area = (3.142*r*s)+(3.142*r*r);
- volume = (1/3)*(3.142*r*r*h);
- printf("Area of cone = %.2f\n", area);
- printf("Volume of cone = %.2f\n", volume);
- //getch();
- }
- void calcircle(void)
- {
- float area = 0;
- float perimeter = 0;
- float r = 0;
- system("CLS");
- printf("Input the side of r : ");
- scanf("%f", &r);
- area = (3.142*r*r);
- perimeter= (2*3.142*r);
- printf("Area of cone = %.2f\n", area);
- printf("Perimeter of cone = %.2f\n", perimeter);
- //getch();
- }
复制代码 对的 Code :- #include <stdio.h>
- #include <math.h>
- #include <windows.h>
- void calsquare(void);
- void calcone(void);
- void calcircle(void);
- int main()
- {
- int y;
- printf("Menu\n");
- printf("1. Find Area and Perimeter of Square\n");
- printf("2. Find Area and Perimeter of Cone\n");
- printf("3. Find Area and Perimeter of a Circle\n");
- printf("4. Quit\n");
- printf("Input the following function\n");
- scanf("%d", &y);
- switch (y)
- {
- case 1:
- calsquare();
- break;
- case 2:
- calcone();
- break;
- case 3:
- calcircle();
- break;
- case 4:
- system("EXIT");
- }
- }
- void calsquare(void)
- {
- float area = 0;
- float perimeter = 0;
- float x = 0;
- system("CLS");
- printf("Input the side of x : ");
- scanf("%f", &x);
- area = (x*x);
- perimeter = (4*x);
- printf("Area of square = %.2f\n", area);
- printf("Perimeter of square = %.2f\n", perimeter);
- //getch();
- }
- void calcone(void)
- {
- float area = 0;
- float volume = 0;
- float s = 0, r = 0, h = 0;
- system("CLS");
- printf("Input the side of s : ");
- scanf("%f", &s);
- printf("Input the side of r : ");
- scanf("%f", &r);
- printf("input the side of h");
- scanf("%f", &h);
- area = (3.142*r*s)+(3.142*r*r);
- volume = (1/3)*(3.142*r*r*h);
- printf("Area of cone = %.2f\n", area);
- printf("Volume of cone = %.2f\n", volume);
- //getch();
- }
- void calcircle(void)
- {
- float area = 0;
- float perimeter = 0;
- float r = 0;
- system("CLS");
- printf("Input the side of r : ");
- scanf("%f", &r);
- area = (3.142*r*r);
- perimeter= (2*3.142*r);
- printf("Area of cone = %.2f\n", area);
- printf("Perimeter of cone = %.2f\n", perimeter);
- //getch();
- }
复制代码 还是那句 , 善用 tab / space 的说 |
|