When i run this code for selection 2 in the menu, after entering the trn number the program displays the investment type without the 1st letter and doesn't do the calculation assigned to it. Also for selection 3 the program runs continuously after selecting option 3 in the menu
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<num;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<num;i++)
{
if(i=num)
{
break;
}
else
{
printf("\n TRN : %s Investment Type : %s",&trn[i],&p_type[i]);
}
if(lowest<i_amount[i])
{
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();
}
getch()orbreakafterreturnhas no effect.char trn[10]-->char trn[10][max string length + 1]scanf(" %s",&trn[i]);the second parameter is not a valid buffer for storing a string. It's a pointer to some part of the array but pretty sure that's not what you want. Same for almost all the other places you have&trn[i]. 2.strcmp(trn[i],trn[i])why comparing something to itself? And in any casetrn[i]is a singlecharnot a string buffer.if(i=num)should beif(i==num). But in fact, there is no need for that conditional block at all. Theforloop already has that built into it. At the start of eachforiteration the checki<numis performed and at the end of eachforloop iterationi++is run.