JBTALKS.CC
标题:
麻烦版主删除
[打印本页]
作者:
god_of_war
时间:
2012-9-8 09:24 AM
标题:
麻烦版主删除
本帖最后由 god_of_war 于 2016-1-14 04:54 PM 编辑
麻烦版主删除
作者:
神龍降世
时间:
2012-9-9 08:21 PM
LZ.. 我看到你的 Code 的时候差点吐血...
为什么你的 Scanf 不用 Store [也就是 '&']
还有 = 是 initialization~ equal 的 sign 是 value1 == value2
getch() 不能 Work, 应该是 Library 的问题~
还有就是你的 Function 没有 Declare..
P/S : 请用善用 Spacebar 和 Tab...
以下是答案 :
#include <stdio.h>
#include <math.h>
#include <windows.h>
void calsquare(void);
void calcone(void);
void calcircle(void);
int main()
{
int y = 0;
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);
if (y == 1) {
calsquare();
}
if (y == 2) {
calcone();
}
if (y == 3) {
calcircle();
}
if (y == 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();
}
复制代码
Pastebin Link :
http://pastebin.com/C2zK3a9J
作者:
black7white
时间:
2012-9-11 12:10 AM
c没学,只会c++
大概看了楼主的code,好像是才学
为什么不用switch,多数这种比较少用if 的,虽然是一样东西啦
作者:
black7white
时间:
2012-9-11 12:13 AM
如果你不要像二楼那样放开头的void,可以选择把int main()放最下面
当我看到void main(),晕了@@
作者:
god_of_war
时间:
2012-9-11 09:29 AM
回复
2#
神龍降世
感谢大大的指导
我将会改进我的错误
作者:
god_of_war
时间:
2012-9-11 09:30 AM
回复
3#
black7white
对,我是刚刚才学的,还不够成熟,话说switch是指case statement吗?
我大约看了source code的example,但是一直出现error
作者:
god_of_war
时间:
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的话
这个是我的写法
#include <stdio.h>
#include <math.h>
#include <windows.h>
void calsquare(void);
void calcone(void);
void calcircle(void);
int main()
{
char 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("%s", &y);
switch(y)
{
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();
}
复制代码
我不知道我的case statement是不是对的
但是整个hang在那里跑不到
也没有反应代码显示无错误
作者:
神龍降世
时间:
2012-9-11 11:39 AM
回复
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 的说
欢迎光临 JBTALKS.CC (https://jbtalks.my/)
Powered by Discuz! X2.5