Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Warencode.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
- //
- #include "stdafx.h"
- string Fehlercode[3] = { "kein Fehler", " String enthält nicht ausschließlich Ziffern", "Nettogewicht ist größer als Bruttogewicht" };
- string code;
- int brutto = 0;
- int netto = 0;
- int tmp = 1;
- char a;
- int main()
- {
- //cin >> code;
- code = "000024740002506831001250";
- for (int anz = 1; anz <= 23; anz++) //Überprüfung des Codes auf nicht Buchstaben
- {
- if (!(code[anz - 1] >= 48 && code[anz - 1] <= 57))
- {
- cout << Fehlercode[1] << endl;
- return 0;
- }
- }
- for (int anz = 13; anz >= 8; anz--) //Auslesen des Netto gewichts
- {
- a = code[anz];
- netto += (a - 48)*tmp;
- tmp *= 10;
- }
- tmp = 1;
- for (int anz = 23; anz >= 18; anz--) //Auslesen des Brutto gewichts
- {
- a = code[anz];
- brutto += (a - 48)*tmp;
- tmp *= 10;
- }
- if (netto > brutto)
- cout << Fehlercode[2] << endl;
- else
- cout << Fehlercode[0] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement