c语言数组常见错误,C语言中的数组错误

当我在菜单中为选择2运行此代码时,输​​入trn编号后,程序将显示没有第一个字母的投资类型,并且不执行分配给它的计算。也为选择3程序在菜单C语言中的数组错误

switch(option)

{

case 1:

system("cls");

printf(" How many clients are to be signed up ? \n");

scanf(" %d",&num);

system("cls");

for(i=0;i

{

printf("\n Investment Type Available");

printf("\n 1. Bonds 2. Stocks 3. MutualFund");

printf("\n ");

printf(" Enter the clients data \n");

printf(" TRN : ");

scanf(" %s",&trn[i]);

printf("\n Investment Type : ");

scanf(" %s",&p_type[i]);

printf("\n Amount Investing : ");

scanf(" %lf",&i_amount[i]);

system("cls");

t_amount=t_amount+i_amount[i];

}

getch();

goto Menu;

break;

case 2:

printf("\n Enter clients TRN : ");

scanf("%s",&trn[i]);

if(strcmp(trn[i],trn[i])==0)

{

printf("\n Investment type for this client : %s",&p_type[i]);

}

else

{

printf("No record found for this client");

getch();

return 0;

}

printf("\n TRN : %s",&trn[i]);

printf("\n Investment Type : %s",&p_type[i]);

printf("\n Interest to be received : $%0.2lf",s_interest);

getch();

goto Menu;

break;

case 3:

printf("Each clients TRN & Investment Type :");

for(i=0;i

{

if(i=num)

{

break;

}

else

{

printf("\n TRN : %s Investment Type : %s",&trn[i],&p_type[i]);

}

if(lowest

{

lowest=i_amount[i];

}

}

a_amount=t_amount/num;

printf("The average amount that could be invested per person is : $%0.2lf",&a_amount);

printf("The client with the least amount to invest ");

break;

case 4:

printf("Exiting system");

getch();

return 0;

break;

default :

printf("Invalid selection");

getch();

return 0;

}

}

return 0;

getch();

}

+0

将您的代码降低到展示您的问题所需的最低限度。还要注意,在'return'后执行'getch()'或'break'不起作用。 –

+0

谢谢@JohnZwinck –

+0

也许'char trn [10]' - >'char trn [10] [最大字符串长度+ 1]' –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值