求大神看看,简单的问题,看看出在哪!!!
/*输入产品号,产品数量,计算总价
*/
#include<stdio.h>
#include <string.h>
int main( void )
{
// 初始化
int i;
int s; //产品号
int q; // 产品数量
double count[6] = {0};
double total = 0;
while( 1 ){
printf( "please enter the number: \n" );
scanf( "%d", &s );
if( s == -1 ) break;
scanf( "%d", &q );
// 不同的产品好,计算不同的总价
switch( s ){
case 1 : count[1] += q * 2.98;
break;
case 2 : count[2] += q * 4.50;
break;
case 3 : count[3] += q * 9.98;
break;
case 4 : count[4] += q * 4.49;
break;
case 5 : count[5] += q * 6.87;
break;
case ' ':
case '\t':
case '\n':
break;
default: printf( "the number is wrong!!\n" );
break;
}// end switch
}// end while
//计算总价
for( i = 1; i <= 6; i++ ){
total += count[i];
}// end for_i
printf( "the totla money is %d!!!\n", total );
return 0;
}// end main function
// 打个比方啊,本来我输入1,2,-1,按我的思路是输出5.96的,怎么老是输出2啊,