Hilfe fuer einen Anfaenger
-
Guten Abend,
ich habe einen Code in C-Sprache geschrieben fuer meinen Unterricht und komme mit ein oder zwei befehlen nicht klar.
#include <stdio.h> #include <ctype.h> int main() { float Eur = 0.793777, CHF = 1.23850, GBP = 0.558036, JPY = 106.860, SAR = 3.75010;/*Declaring constant value*/ float result1,result2,result3,result4,result5, amount;/* Declaring variable*/ char input;/* Declaring variable*/ /* Title of Program */ printf("\t CURRENCY CONVERSION PROGRAM\n\n"); /* Output Statements */ printf("\t\t 1. Europe\n"); /* Displays currency name*/ printf("\t\t 2. Switzerland\n"); /* Displays currency name*/ printf("\t\t 3. England\n"); /* Displays currency name*/ printf("\t\t 4. Japan\n"); /* Displays currency name*/ printf("\t\t 5. Saudi Arabia\n\n"); /* Displays currency name*/ printf("\t Select country by pressing 1-5 or press (q) to exit\n\n"); scanf("%c", &input);/*Asks user input*/ tolower(input); while ( input != 'q') { if (isdigit(input)) { printf("\b Wrong entry, try again...\n"); } if(input == '1') { printf("\b You have selected Europe\n"); printf("\b Enter Euro amount to convert and press enter:\n\n"); scanf("%f", &amount);/*Asks user input*/ result1 = Eur * amount;/*Harcoded equation*/ printf("The transaction will provide you with: %1.2f USD\n\n", result1); } else if(input == '2') { printf("\b You have selected Switzerland\n"); printf("\b Enter amount of Swiss Francs to convert and press enter:\n\n"); scanf("%f", &amount);/*Asks user input*/ result2 = CHF * amount;/*Harcoded equation*/ printf("The transaction will provide you with: %1.2f USD\n\n", result2); } else if(input == '3') { printf("\b You have selected England\n"); printf("\b Enter amount of British Pounds to convert and press enter:\n\n"); scanf("%f", &amount);/*Asks user input*/ result3 = GBP * amount;/*Harcoded equation*/ printf("The transaction will provide you with: %1.2f USD\n\n", result3); } else if(input == '4') { printf("\b You have selected Japan\n"); printf("\b Enter amount of Japanese Yens to convert and press enter:\n\n"); scanf("%f", &amount);/*Asks user input*/ result4 = JPY * amount;/*Harcoded equation*/ printf("The transaction will provide you with: %1.2f USD\n\n", result4); } else if(input == '5') { printf("\b You have selected Saudi Arabia\n"); printf("\b Enter amount of Saudi arabia Riyals to convert and press enter:\n\n"); scanf("%f", &amount);/*Asks user input*/ result5 = SAR * amount;/*Harcoded equation*/ printf("The transaction will provide you with: %1.2f USD\n\n", result5); } fflush(stdin); printf("\t Select country by pressing 1-5 or press (q) to exit\n\n"); scanf("%c", &input);/*Asks user input*/ } exit(1); getchar(); /* Allows statements to be displayed on screen */ return 0; } /***********************End of Currency Conversion Program******************************/
Wenn das Programm fraegt das man ein Land auswaehlen soll nimmt er den Befehl an... Aber bringt gleichzeitig die Fehlermeldung die ich Defeniert habe.
Desweiteren bei Eingabe eines Betrags. Wenn eine Zahl eingegeben wird konvertiert er es ohne Probleme. Bei eingabe eines Buchstaben ebenfalls
Seht euch doch bitte den Code mal an und weist mich auf meine Fehler hin.
Vielen Dank
schoenen Abend
Daniel
-
Dieser Thread wurde von Moderator/in evilissimo aus dem Forum C++/CLI mit .NET in das Forum ANSI C verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
zum fehler - sollte das evtl nen
if(!isdigit(input)) { fehlermeldung ausgeben ...
werden
wenn er nen digit eingibt ist es ja richtig - und das ! negiert das ganze um rauszubekommen ob er kein digit eingegeben hat - und dann muss er ja den fehler bringen
der code ist grauenhaft und wahnsinnig schlecht lesbar
-> keiner wird das ernsthaft genauer kontrollieren wolleneigentlich ist es schon nen grobes verbrechen das du sooooo viel doppelten code hast und soooo viele vollkommen nutzlose kommentare
-
Ähm - Mehrfachpost?
[ edit by c.rackwitz: locked und Amen ]