-1

I trying to create something where the user has to give certain numbers and at the end the program prints all the numbers with a space in between. Everything is working, except the last printf(). I have tried to fflush in and out like the previous scanf() but nothing works.

Any suggestions? Here is the code:

printf("Give a round number:\n");
fflush(stdout);
scanf("%d", &roundNumber);
fflush(stdin);

printf("Give a decimal number:\n");
fflush(stdout);
scanf("%lf", &decimalNumber);
fflush(stdin);

printf("Give 2 round numbers separated by a ',' :\n");
fflush(stdout);
scanf("%d,%d",firstRoundNumber,secondRoundNumber);
fflush(stdin);

printf("Your numbers: %d %lf %d %d\n", roundNumber, decimalNumber, firstRoundNumber, secondRoundNumber);
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
MatsAZ456
  • 29
  • 5
  • scanf("%d,%d",&firstRoundNumber,&secondRoundNumber); – Tanvir Sourov May 19 '17 at 21:03
  • `scanf("%d,%d",firstRoundNumber,secondRoundNumber); -> scanf("%d,%d",&firstRoundNumber,&secondRoundNumber);` – RoiHatam May 19 '17 at 21:03
  • 3
    Also, 'fflush(stdin);' is UB. – ThingyWotsit May 19 '17 at 21:05
  • Also, debug fail - stepping through would have shown that the printf() was not even reached. – ThingyWotsit May 19 '17 at 21:13
  • Here is a handy link with the C11 standard referenced [**what is the use of fflush(stdin) in c programming**](http://stackoverflow.com/questions/18170410/what-is-the-use-of-fflushstdin-in-c-programming). Also, if you just enclose your in-line code in comments in *backticks* (e.g. `\`stuff\``) it will be offset as fixed-width. – David C. Rankin May 19 '17 at 21:23

1 Answers1

0

You wrote

scanf("%d,%d",firstRoundNumber,secondRoundNumber);

You forgot to use variables adresses for the last scanf :

scanf("%d,%d", &firstRoundNumber, &secondRoundNumber);
Barmar
  • 741,623
  • 53
  • 500
  • 612
MIG-23
  • 511
  • 3
  • 11