Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 2057|回复: 7
打印 上一主题 下一主题

麻烦版主删除

[复制链接]

33

主题

0

好友

1477

积分

黄金长老

Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8

跳转到指定楼层
1#
发表于 2012-9-8 09:24 AM |只看该作者 |倒序浏览
本帖最后由 god_of_war 于 2016-1-14 04:54 PM 编辑

麻烦版主删除




收藏收藏0

5

主题

0

好友

584

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

2#
发表于 2012-9-9 08:21 PM |只看该作者
LZ.. 我看到你的 Code 的时候差点吐血...

为什么你的 Scanf 不用 Store [也就是 '&']

还有 = 是 initialization~ equal 的 sign 是 value1 == value2

getch() 不能 Work, 应该是 Library 的问题~

还有就是你的 Function 没有 Declare..

P/S : 请用善用 Spacebar 和 Tab...

以下是答案 :
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <windows.h>

  4. void calsquare(void);
  5. void calcone(void);
  6. void calcircle(void);

  7. int main()
  8. {

  9.         int y = 0;

  10.         printf("Menu\n");
  11.         printf("1. Find Area and Perimeter of Square\n");
  12.         printf("2. Find Area and Perimeter of Cone\n");
  13.         printf("3. Find Area and Perimeter of a Circle\n");
  14.         printf("4. Quit\n");
  15.         printf("Input the following function\n");
  16.         scanf("%d", &y);

  17.         if (y == 1) {
  18.         calsquare();
  19.         }

  20.         if (y == 2) {
  21.         calcone();
  22.         }

  23.         if (y == 3) {
  24.         calcircle();
  25.         }

  26.         if (y == 4) {
  27.         system("EXIT");
  28.         }
  29. }
  30.          
  31. void calsquare(void)
  32. {

  33.         float area = 0;
  34.         float perimeter = 0;
  35.         float x = 0;
  36.         system("CLS");

  37.         printf("Input the side of x : ");
  38.         scanf("%f", &x);

  39.         area = (x*x);
  40.         perimeter = (4*x);

  41.         printf("Area of square = %.2f\n", area);
  42.         printf("Perimeter of square = %.2f\n", perimeter);

  43.         //getch();
  44. }

  45. void calcone(void)
  46. {

  47.         float area = 0;
  48.         float volume = 0;
  49.         float s = 0, r = 0, h = 0;

  50.         system("CLS");
  51.         printf("Input the side of s : ");
  52.         scanf("%f", &s);

  53.         printf("Input the side of r : ");
  54.         scanf("%f", &r);

  55.         printf("input the side of h");
  56.         scanf("%f", &h);

  57.         area = (3.142*r*s)+(3.142*r*r);
  58.         volume = (1/3)*(3.142*r*r*h);

  59.         printf("Area of cone = %.2f\n", area);
  60.         printf("Volume of cone = %.2f\n", volume);

  61.         //getch();
  62. }

  63. void calcircle(void)
  64. {

  65.         float area = 0;
  66.         float perimeter = 0;
  67.         float r = 0;

  68.         system("CLS");
  69.         printf("Input the side of r : ");
  70.         scanf("%f", &r);

  71.         area = (3.142*r*r);
  72.         perimeter= (2*3.142*r);

  73.         printf("Area of cone = %.2f\n", area);
  74.         printf("Perimeter of cone = %.2f\n", perimeter);

  75.         //getch();
  76. }
复制代码
Pastebin Link : http://pastebin.com/C2zK3a9J


回复

使用道具 举报

142

主题

2

好友

7827

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

3#
发表于 2012-9-11 12:10 AM |只看该作者
c没学,只会c++
大概看了楼主的code,好像是才学
为什么不用switch,多数这种比较少用if 的,虽然是一样东西啦


回复

使用道具 举报

142

主题

2

好友

7827

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

4#
发表于 2012-9-11 12:13 AM |只看该作者
如果你不要像二楼那样放开头的void,可以选择把int main()放最下面
当我看到void main(),晕了@@


回复

使用道具 举报

33

主题

0

好友

1477

积分

黄金长老

Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8

5#
发表于 2012-9-11 09:29 AM |只看该作者
回复 2# 神龍降世


   感谢大大的指导
我将会改进我的错误


回复

使用道具 举报

33

主题

0

好友

1477

积分

黄金长老

Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8

6#
发表于 2012-9-11 09:30 AM |只看该作者
回复 3# black7white


对,我是刚刚才学的,还不够成熟,话说switch是指case statement吗?
我大约看了source code的example,但是一直出现error


回复

使用道具 举报

33

主题

0

好友

1477

积分

黄金长老

Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8

7#
发表于 2012-9-11 10:26 AM |只看该作者
本帖最后由 god_of_war 于 2012-9-11 10:30 AM 编辑
LZ.. 我看到你的 Code 的时候差点吐血...  

为什么你的 Scanf 不用 Store [也就是 '&']

还有 ...
神龍降世 发表于 9-9-2012 20:21



大大
我如果用case statement的话
这个是我的写法
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <windows.h>

  4. void calsquare(void);
  5. void calcone(void);
  6. void calcircle(void);

  7. int main()
  8. {

  9.         char y;

  10.         printf("Menu\n");
  11.         printf("1. Find Area and Perimeter of Square\n");
  12.         printf("2. Find Area and Perimeter of Cone\n");
  13.         printf("3. Find Area and Perimeter of a Circle\n");
  14.         printf("4. Quit\n");
  15.         printf("Input the following function\n");
  16.         scanf("%s", &y);

  17.         switch(y)
  18.         {

  19.         case “1”:
  20.         calsquare()();
  21.         break;
  22.         case “2”:
  23.         calcone();
  24.         break;
  25.         case “3”:
  26.         calcircle();
  27.         break;
  28.         case “4”:
  29.         system("EXIT");
  30.         break;

  31.         }

  32. }

  33. void calsquare(void)
  34. {

  35.         float area = 0;
  36.         float perimeter = 0;
  37.         float x = 0;
  38.         system("CLS");

  39.         printf("Input the side of x : ");
  40.         scanf("%f", &x);

  41.         area = (x*x);
  42.         perimeter = (4*x);

  43.         printf("Area of square = %.2f\n", area);
  44.         printf("Perimeter of square = %.2f\n", perimeter);

  45.         //getch();
  46. }

  47. void calcone(void)
  48. {

  49.         float area = 0;
  50.         float volume = 0;
  51.         float s = 0, r = 0, h = 0;

  52.         system("CLS");
  53.         printf("Input the side of s : ");
  54.         scanf("%f", &s);

  55.         printf("Input the side of r : ");
  56.         scanf("%f", &r);

  57.         printf("input the side of h");
  58.         scanf("%f", &h);

  59.         area = (3.142*r*s)+(3.142*r*r);
  60.         volume = (1/3)*(3.142*r*r*h);

  61.         printf("Area of cone = %.2f\n", area);
  62.         printf("Volume of cone = %.2f\n", volume);

  63.         //getch();
  64. }

  65. void calcircle(void)
  66. {

  67.         float area = 0;
  68.         float perimeter = 0;
  69.         float r = 0;

  70.         system("CLS");
  71.         printf("Input the side of r : ");
  72.         scanf("%f", &r);

  73.         area = (3.142*r*r);
  74.         perimeter= (2*3.142*r);

  75.         printf("Area of cone = %.2f\n", area);
  76.         printf("Perimeter of cone = %.2f\n", perimeter);

  77.         //getch();
  78. }
复制代码



我不知道我的case statement是不是对的
但是整个hang在那里跑不到
也没有反应代码显示无错误


回复

使用道具 举报

5

主题

0

好友

584

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

8#
发表于 2012-9-11 11:39 AM |只看该作者
回复 7# god_of_war

首先告诉你哪里 Salah :
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <windows.h>

  4. void calsquare(void);
  5. void calcone(void);
  6. void calcircle(void);

  7. int main()
  8. {

  9.         char y; //这里错, y 的 data type 必须是 int, 因为你的 Selection 是写 1 / 2 / 3 / 4 的.. 如果 char 的话是 a b c..

  10.         printf("Menu\n");
  11.         printf("1. Find Area and Perimeter of Square\n");
  12.         printf("2. Find Area and Perimeter of Cone\n");
  13.         printf("3. Find Area and Perimeter of a Circle\n");
  14.         printf("4. Quit\n");
  15.         printf("Input the following function\n");
  16.         scanf("%s", &y); //这里错, %d 才对, 因为读取的是 integer / digit

  17.         switch(y)
  18.         {

  19.         case “1”: //这里错, case 1: 就可以了, 并不用放任何符号, 而且你的符号也是错的, 你这边用的符号是华文输入法的开关引号 ..
  20.         calsquare()(); //这里错, 怎么两个 () () ~
  21.         break;
  22.         case “2”: //这里错, 同上
  23.         calcone();
  24.         break;
  25.         case “3”: //这里错, 同上
  26.         calcircle();
  27.         break;
  28.         case “4”: //这里错, 同上
  29.         system("EXIT");
  30.         break; //可有可无

  31.         }

  32. }

  33. void calsquare(void)
  34. {

  35.         float area = 0;
  36.         float perimeter = 0;
  37.         float x = 0;
  38.         system("CLS");

  39.         printf("Input the side of x : ");
  40.         scanf("%f", &x);

  41.         area = (x*x);
  42.         perimeter = (4*x);

  43.         printf("Area of square = %.2f\n", area);
  44.         printf("Perimeter of square = %.2f\n", perimeter);

  45.         //getch();
  46. }

  47. void calcone(void)
  48. {

  49.         float area = 0;
  50.         float volume = 0;
  51.         float s = 0, r = 0, h = 0;

  52.         system("CLS");
  53.         printf("Input the side of s : ");
  54.         scanf("%f", &s);

  55.         printf("Input the side of r : ");
  56.         scanf("%f", &r);

  57.         printf("input the side of h");
  58.         scanf("%f", &h);

  59.         area = (3.142*r*s)+(3.142*r*r);
  60.         volume = (1/3)*(3.142*r*r*h);

  61.         printf("Area of cone = %.2f\n", area);
  62.         printf("Volume of cone = %.2f\n", volume);

  63.         //getch();
  64. }

  65. void calcircle(void)
  66. {

  67.         float area = 0;
  68.         float perimeter = 0;
  69.         float r = 0;

  70.         system("CLS");
  71.         printf("Input the side of r : ");
  72.         scanf("%f", &r);

  73.         area = (3.142*r*r);
  74.         perimeter= (2*3.142*r);

  75.         printf("Area of cone = %.2f\n", area);
  76.         printf("Perimeter of cone = %.2f\n", perimeter);

  77.         //getch();
  78. }
复制代码
对的 Code :
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <windows.h>

  4. void calsquare(void);
  5. void calcone(void);
  6. void calcircle(void);

  7. int main()
  8. {

  9.         int y;

  10.         printf("Menu\n");
  11.         printf("1. Find Area and Perimeter of Square\n");
  12.         printf("2. Find Area and Perimeter of Cone\n");
  13.         printf("3. Find Area and Perimeter of a Circle\n");
  14.         printf("4. Quit\n");
  15.         printf("Input the following function\n");
  16.         scanf("%d", &y);

  17.         switch (y)
  18.         {

  19.         case 1:
  20.         calsquare();
  21.         break;

  22.         case 2:
  23.         calcone();
  24.         break;

  25.         case 3:
  26.         calcircle();
  27.         break;

  28.         case 4:
  29.         system("EXIT");

  30.         }

  31. }

  32. void calsquare(void)
  33. {

  34.         float area = 0;
  35.         float perimeter = 0;
  36.         float x = 0;
  37.         system("CLS");

  38.         printf("Input the side of x : ");
  39.         scanf("%f", &x);

  40.         area = (x*x);
  41.         perimeter = (4*x);

  42.         printf("Area of square = %.2f\n", area);
  43.         printf("Perimeter of square = %.2f\n", perimeter);

  44.         //getch();
  45. }

  46. void calcone(void)
  47. {

  48.         float area = 0;
  49.         float volume = 0;
  50.         float s = 0, r = 0, h = 0;

  51.         system("CLS");
  52.         printf("Input the side of s : ");
  53.         scanf("%f", &s);

  54.         printf("Input the side of r : ");
  55.         scanf("%f", &r);

  56.         printf("input the side of h");
  57.         scanf("%f", &h);

  58.         area = (3.142*r*s)+(3.142*r*r);
  59.         volume = (1/3)*(3.142*r*r*h);

  60.         printf("Area of cone = %.2f\n", area);
  61.         printf("Volume of cone = %.2f\n", volume);

  62.         //getch();
  63. }

  64. void calcircle(void)
  65. {

  66.         float area = 0;
  67.         float perimeter = 0;
  68.         float r = 0;

  69.         system("CLS");
  70.         printf("Input the side of r : ");
  71.         scanf("%f", &r);

  72.         area = (3.142*r*r);
  73.         perimeter= (2*3.142*r);

  74.         printf("Area of cone = %.2f\n", area);
  75.         printf("Perimeter of cone = %.2f\n", perimeter);

  76.         //getch();
  77. }
复制代码
还是那句 , 善用 tab / space 的说


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-6-30 10:54 PM , Processed in 0.118303 second(s), 26 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部