user-0 提问: 有谁电脑上有VC6的帮我看看这段SWITCH语句有什么问题

回复:
user: user-0
content: 刚才重装了系统，没问题了，原来的程序也是正确的，看来确实是系统出了问题了 谢谢楼上各位，这个没问题了，分不多，热心的朋友又这么多，只能每个人意思一下了 但你们的热情和爱心是分数不能衡量的：）

user: user-1
content: 我记得float 在存储过程中是有误差的，如果我 输入 99.99999 再  (int) 99.9999/10   如  #include <stdio.h>; int main(void) {    float i = 99.999999999999999;         printf(" i = %d\n", (int)i/10);      return 0; }   在VC++ 6.0输出的结果就是，虽然分数是不可能是这样子。。。  ------------------------------------------------  i = 10 Press any key to continue ---------------------------------------------------

user: user-0
content: 确实没问题，我当时可能是电脑出了错了 我最近电脑出了问题了，正准备重新做个系统

user: user-2
content: lz你的VC6.0什么版的啊？ 我的是完整绿色版，没问题啊

user: user-0
content: 引用 10 楼 u013595256 的回复:[quote=引用 9 楼 romabdwy 的回复:] 我刚才试了上面的三个方案 方案一：在main前面加了void程序正确 方案二：float score=0;程序正确了 方案三：switch ((int)(score/10))这样也正确，将(score/10.0f)弄成这样也是正确的  将方案二和三一起使用也正确，其他组合我就没试了 现在看来是赋值的问题？ 问题出在void main()上面？像这种情况？好像说main推荐的用法是void main()我测试好像没有问题，关于main的问题，现在main只有int main(void)和int main(int argc, char * argv[])两种定义，现在的部分c实现为了兼容之前K&R c的代码才允许void main的[/quote]  嗯将void main()改成int main()也是可以正确执行的，这种问题是什么问题知道吗？如果明天没有人回复我就结贴给分了：）

user: user-3
content: 目测代码没有问题啊，估计是编译器的什么问题

user: user-4
content: 也可能楼主的VC6没打SP6补丁。

user: user-2
content: 引用 12 楼 romabdwy 的回复:嗯将void main()改成int main()也是可以正确执行的，这种问题是什么问题知道吗？如果明天没有人回复我就结贴给分了：） 这种问题为什么真是不太清楚，以前倒也见过几次，都是类似问题，不明白，但我一直是加着void或int，建议lz以后敲代码时也加着吧

user: user-5
content: #include<stdio.h> main() { 	float score; 	scanf("%f",&score); 	switch((int)(score/10)) 	{ 	case 10: 	case  9: printf("Your score is A\n"); break; 	case  8: printf("Your score is B\n"); break; 	case  7: printf("Your score is C\n"); break; 	case  6: printf("Your score is D\n"); break; 	default : printf("Your score is E\n");  	}  }

user: user-6
content: 引用 9 楼 romabdwy 的回复:我刚才试了上面的三个方案 方案一：在main前面加了void程序正确 方案二：float score=0;程序正确了 方案三：switch ((int)(score/10))这样也正确，将(score/10.0f)弄成这样也是正确的  将方案二和三一起使用也正确，其他组合我就没试了 现在看来是赋值的问题？ 问题出在void main()上面？像这种情况？好像说main推荐的用法是void main()我测试好像没有问题，关于main的问题，现在main只有int main(void)和int main(int argc, char * argv[])两种定义，现在的部分c实现为了兼容之前K&R c的代码才允许void main的

user: user-0
content: 我刚才试了上面的三个方案 方案一：在main前面加了void程序正确 方案二：float score=0;程序正确了 方案三：switch ((int)(score/10))这样也正确，将(score/10.0f)弄成这样也是正确的  将方案二和三一起使用也正确，其他组合我就没试了 现在看来是赋值的问题？ 问题出在void main()上面？像这种情况？好像说main推荐的用法是void main()

user: user-4
content: C++ Integer Constants Integer constants are constant data elements that have no fractional parts or exponents. They always begin with a digit. You can specify integer constants in decimal, octal, or hexadecimal form. They can specify signed or unsigned types and long or short types.  Syntax  integer-constant :  decimal-constant integer-suffixopt octal-constant integer-suffixopt hexadecimal-constant integer-suffixopt 'c-char-sequence'  decimal-constant :  nonzero-digit decimal-constant digit  octal-constant :  0 octal-constant octal-digit  hexadecimal-constant :  0x hexadecimal-digit 0X hexadecimal-digit hexadecimal-constant hexadecimal-digit  nonzero-digit : one of  1 2 3 4 5 6 7 8 9  octal-digit : one of  0 1 2 3 4 5 6 7  hexadecimal-digit : one of  0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F  integer-suffix :  unsigned-suffix long-suffixopt long-suffix unsigned-suffixopt  unsigned-suffix : one of  u U  long-suffix : one of  l L  64-bit integer-suffix :  i64  To specify integer constants using octal or hexadecimal notation, use a prefix that denotes the base. To specify an integer constant of a given integral type, use a suffix that denotes the type.  To specify a decimal constant, begin the specification with a nonzero digit. For example:  int i = 157;   // Decimal constant int j = 0198;  // Not a decimal number; erroneous octal constant int k = 0365;  // Leading zero specifies octal constant, not decimal  To specify an octal constant, begin the specification with 0, followed by a sequence of digits in the range 0 through 7. The digits 8 and 9 are errors in specifying an octal constant. For example:  int i = 0377;   // Octal constant int j = 0397;   // Error: 9 is not an octal digit  To specify a hexadecimal constant, begin the specification with 0x or 0X (the case of the “x” does not matter), followed by a sequence of digits in the range 0 through 9 and a (or A) through f (or F). Hexadecimal digits a (or A) through f (or F) represent values in the range 10 through 15. For example:  int i = 0x3fff;   // Hexadecimal constant int j = 0X3FFF;   // Equal to i  To specify an unsigned type, use either the u or U suffix. To specify a long type, use either the l or L suffix. For example:  unsigned uVal = 328u;             // Unsigned value long lVal = 0x7FFFFFL;            // Long value specified                                    //  as hex constant unsigned long ulVal = 0776745ul;  // Unsigned long value

user: user-4
content: 常量也有类型！ C++ Floating-Point Constants Floating-point constants specify values that must have a fractional part. These values contain decimal points (.) and can contain exponents.  Syntax  floating-constant :  fractional-constant exponent-partopt floating-suffixopt digit-sequence exponent-part floating-suffixopt  fractional-constant :  digit-sequenceopt . digit-sequence digit-sequence .  exponent-part :  e signopt digit-sequence E signopt digit-sequence  sign : one of  + –  digit-sequence :  digit digit-sequence digit  floating-suffix :one of  f l F L  Floating-point constants have a “mantissa,” which specifies the value of the number, an “exponent,” which specifies the magnitude of the number, and an optional suffix that specifies the constant’s type. The mantissa is specified as a sequence of digits followed by a period, followed by an optional sequence of digits representing the fractional part of the number. For example:  18.46 38.  The exponent, if present, specifies the magnitude of the number as a power of 10, as shown in the following example:  18.46e0      // 18.46 18.46e1      // 184.6  If an exponent is present, the trailing decimal point is unnecessary in whole numbers such as 18E0.  Floating-point constants default to type double. By using the suffixes f or l (or F or L — the suffix is not case sensitive), the constant can be specified as float or long double, respectively.  Although long double and double have the same representation, they are not the same type. For example, you can have overloaded functions like  void func( double );  and   void func( long double );

user: user-4
content: 引用 5 楼 cocodada 的回复:[quote=引用 2 楼 zhao4zhong1 的回复:] #include<stdio.h> main() {     float score=0.0f;     scanf("%f",&score);     switch((int)(score/10.0f))     {     case 10:     case  9: printf("Your score is A\n"); break;     case  8: printf("Your score is B\n"); break;     case  7: printf("Your score is C\n"); break;     case  6: printf("Your score is D\n"); break;     default : printf("Your score is E\n");      }   }  score是浮点数，在和10运算的时候，10不是会自动类型转换成浮点数类型的么？[/quote] 不要迷信书、考题、老师、回帖； 要迷信CPU、编译器、调试器、运行结果。 并请结合“盲人摸太阳”和“驾船出海时一定只带一个指南针。”加以理解。 任何理论、权威、传说、真理、标准、解释、想象、知识……都比不上摆在眼前的事实！  有人说一套做一套，你相信他说的还是相信他做的？ 其实严格来说这个世界上古往今来所有人都是说一套做一套，不是吗？  不要写连自己也预测不了结果的代码！

user: user-7
content: 引用 2 楼 zhao4zhong1 的回复:#include<stdio.h> main() {     float score=0.0f;     scanf("%f",&score);     switch((int)(score/10.0f))     {     case 10:     case  9: printf("Your score is A\n"); break;     case  8: printf("Your score is B\n"); break;     case  7: printf("Your score is C\n"); break;     case  6: printf("Your score is D\n"); break;     default : printf("Your score is E\n");      }   }  score是浮点数，在和10运算的时候，10不是会自动类型转换成浮点数类型的么？

user: user-8
content: 同志，vc6太老，有bug的，在vc6中float是要初始化的 #include<stdio.h> main() {     float score=0;     scanf("%f",&score);     switch((int)score/10)     {     case 10:     case  9: printf("Your score is A\n"); break;     case  8: printf("Your score is B\n"); break;     case  7: printf("Your score is C\n"); break;     case  6: printf("Your score is D\n"); break;     default : printf("Your score is E\n");      }   }

user: user-9
content: 没有VC6，也没看出有什么问题。 不过main()这个还是写全的好。  #include <stdio.h>  int main(void) { 	float score; 	scanf("%f", &score); 	switch((int)score/10) 	{ 	case 10: 	case  9: printf("Your score is A\n"); break; 	case  8: printf("Your score is B\n"); break; 	case  7: printf("Your score is C\n"); break; 	case  6: printf("Your score is D\n"); break; 	default: printf("Your score is E\n");  	}  	return 0; }

user: user-4
content: #include<stdio.h> main() {     float score=0.0f;     scanf("%f",&score);     switch((int)(score/10.0f))     {     case 10:     case  9: printf("Your score is A\n"); break;     case  8: printf("Your score is B\n"); break;     case  7: printf("Your score is C\n"); break;     case  6: printf("Your score is D\n"); break;     default : printf("Your score is E\n");      }   }

user: user-4
content: switch((int)score/10) 似应改为 switch((int)(score/10.0f))