Cześć.
Ucze się wykorzystywania funkcji żeby nie pisać kodu spaghetti tylko robić programy skladajace sie z podprogramow.
Nie mam pojecia zielonego dlaczego wywala mi -1 przy wyborze opcji nr 1 i przechodzi dalej przy wybraniu opcji nr 2.
Oto kod:
#include <stdio.h>
void SharesManagement (int cash,int Value_Of_Share,int Number_Of_Sector_Shares,char Name_Of_Sector);
int main()
{
char Finance [] = "Financial Sector";
int Value_Of_Share_Finances,cash=100000,Number_Of_Shares_Finance;
SharesManagement(cash,Value_Of_Share_Finances,Number_Of_Shares_Finance,*Finance);
return 0;
}
void SharesManagement (int cash,int Value_Of_Share,int Number_Of_Sector_Shares,char Name_Of_Sector)
{
int Choice,Number_Of_Shares;
printf("Would you like to buy or sell?\n");
printf("1.I'd like to buy\n");
printf("2.I'd like to sell\n");
scanf("%d",&Choice);
if(Choice==1)
{
printf("How many shares of %c would you like to buy? (maximum is: %d\n)",Name_Of_Sector,(cash/Value_Of_Share));
scanf("%d",&Number_Of_Shares);
if(Number_Of_Shares*Value_Of_Share>cash){printf("Insufficient funds\n");}
cash=cash-Number_Of_Sector_Shares*Value_Of_Share;
Number_Of_Sector_Shares=Number_Of_Sector_Shares+Number_Of_Shares;
}
else
{
printf("How many shares of %c would you like to sell?\n"),Name_Of_Sector;
scanf("%d",&Number_Of_Shares);
if(Number_Of_Shares>Number_Of_Sector_Shares){printf("You don't have these shares!\n");}
cash=cash+Number_Of_Shares*Value_Of_Share;
Number_Of_Sector_Shares=Number_Of_Sector_Shares-Number_Of_Shares;
}
}
Proszę o sugestie/konstruktywną krytykę/ironiczne komentarze z których mogę się czegoś nauczyć - cokolwiek.
while(getchar()!='\n') {}