Program ignoruje wczytywaną zmienna
Ostatnio zmodyfikowano 2014-10-20 19:56
gero1913 Temat założony przez niniejszego użytkownika |
Program ignoruje wczytywaną zmienna » 2014-10-20 19:39:39 Cześć.
Oto link do kodu: http://wklej.to/JPsj1
Problem jest taki ze po skompilowaniu go i wyborze opcji "1" czyli ze chce kupic, program po prostu sie konczy i go wywala mimo iż jest przy scanf '&'.
Jakieś sugestie? |
|
Rashmistrz |
» 2014-10-20 19:46:40 WOW. //Ten kod jest dość "puszysty". Sformatowałem go według własnego stylu. :F #include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h>
void Akcje( int cash, int Value_Of_Share, int Number_Of_Sector_Shares, char * NameOfSector );
int main( int argc, char * argv[] ) { srand( time( NULL ) ); int Value_Of_Assets = 0, Number_Of_Rounds, Choice, Number_Of_Shares, Cash = 100000; int round = 1, Value_Of_Share_IT, Value_Of_Share_Media, Value_Of_Share_Finances, Value_Of_Share_Infrastructure, Value_Of_Share_Energetics; int Number_Of_Shares_IT, Number_Of_Shares_Media, Number_Of_Shares_Finances, Number_Of_Shares_Infrastructure, Number_Of_Shares_Energetics; Number_Of_Shares_IT = Number_Of_Shares_Media = Number_Of_Shares_Finances = Number_Of_Shares_Infrastructure = Number_Of_Shares_Energetics = 0; Value_Of_Share_IT = Value_Of_Share_Media = Value_Of_Share_Finances = Value_Of_Share_Infrastructure = Value_Of_Share_Energetics = 100; char Finance[] = "Financial Sector"; Akcje( Cash, Value_Of_Share_Finances, Number_Of_Shares_Finances, Finance ); return 0; }
void Akcje( int Cash, int Value_Of_Share_Sector, int Number_Of_Shares_Sector, char * NameOfSector ) { 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 %s would you like to buy? (maximum is %d)\n" ), NameOfSector, ( Cash / Value_Of_Share_Sector ); scanf( "%d", & Number_Of_Shares ); if( Number_Of_Shares_Sector * Value_Of_Share_Sector > Cash ) { printf( "Insufficient funds\n" ); } Cash = Cash - Number_Of_Shares * Value_Of_Share_Sector; Number_Of_Shares_Sector = Number_Of_Shares + Number_Of_Shares_Sector; } else { printf( "How many shares of Financial Sector would you like to sell? \n" ); scanf( "%d", & Number_Of_Shares ); if( Number_Of_Shares > Number_Of_Shares_Sector ) { printf( "You don't have these shares!\n" ); } Cash = Cash + Number_Of_Shares * Value_Of_Share_Sector; Number_Of_Shares_Sector = Number_Of_Shares_Sector - Number_Of_Shares; } }
|
|
pekfos |
» 2014-10-20 19:50:57 printf( "How many shares of %s would you like to buy? (maximum is %d)\n" ), NameOfSector,( Cash / Value_Of_Share_Sector );
|
Nawiasy się nie zgadzają. |
|
gero1913 Temat założony przez niniejszego użytkownika |
» 2014-10-20 19:56:08 Dziękuje panowie !
Co do kodu to oczywiście się zgadzam. Jest to typowy kod spaghetti,nieczytelnie i ogólnie słabo. Dlatego chciałem stworzyć tego voida żeby to nieco poprawić i tak z programu 330 linijek zrobilem 120.
|
|
« 1 » |