atari-home.de - Foren
Software => Coding => Thema gestartet von: afalc060 am Sa 04.09.2010, 21:21:37
-
/* Rechenprogramm */
#include <stdio.h>
int main(void){
int zahl1, zahl2;
printf("\n\n\tRechenprogramm (mit Ganzzahlen, ohne Nachkommastellen)\n");
printf("\nBitte eine Ganzzahl eingeben:");
scanf("%i",&zahl1);
printf("Eine weitere Ganzzahl bitte:");
scanf("%i",&zahl2);
printf("\n%i + %i = %i", zahl1, zahl2, zahl1+zahl2);
printf("\n%i - %i = %i", zahl1, zahl2, zahl1-zahl2);
printf("\n%i * %i = %i", zahl1, zahl2, zahl1*zahl2);
printf("\n%i / %i = %i", zahl1, zahl2, zahl1/zahl2);
printf("\n%i %% %i = %i", zahl1, zahl2, zahl1%zahl2);
printf("\n\n<Return> zum beenden..");
getchar();
return(0);
}
wenn ich beim ersten scanf() zb 20.5 oder anderes eingebe, wird das zweite scanf() übersprungen. wie kann man das verhindern??
edit: getchar() wird auch übersprungen. also auch mit richtiger eingabe..
-
http://pronix.linuxdelta.de/C/standard_C/c_programmierung_6.shtml
...dort Punkt 6.2
also das hier ist die Lösung, jedenfalls unter meinem Linux, unter anderen systemen führts evt. zu ner endlos schleife ^^:
while( getchar() != '\n');
-
die schleife funktioniert. hier mac os x
fflush() tut anscheinend nichts..