Advertisement
Florian-Binder

Warencode C++

Oct 17th, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. // Warencode.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. string Fehlercode[3] = { "kein Fehler", " String enthält nicht ausschließlich Ziffern", "Nettogewicht ist größer als Bruttogewicht" };
  7. string code;
  8. int brutto = 0;
  9. int netto = 0;
  10. int tmp = 1;
  11. char a;
  12.  
  13. int main()
  14. {
  15.     //cin >> code;
  16.     code = "000024740002506831001250";
  17.  
  18.     for (int anz = 1; anz <= 23; anz++) //Überprüfung des Codes auf nicht Buchstaben
  19.     {
  20.         if (!(code[anz - 1] >= 48 && code[anz - 1] <= 57))
  21.         {
  22.             cout << Fehlercode[1] << endl;
  23.             return 0;
  24.         }
  25.     }
  26.  
  27.     for (int anz = 13; anz >= 8; anz--) //Auslesen des Netto gewichts
  28.     {
  29.         a = code[anz];
  30.         netto += (a - 48)*tmp;
  31.         tmp *= 10;
  32.     }
  33.  
  34.     tmp = 1;
  35.  
  36.     for (int anz = 23; anz >= 18; anz--) //Auslesen des Brutto gewichts
  37.     {
  38.         a = code[anz];
  39.         brutto += (a - 48)*tmp;
  40.         tmp *= 10;
  41.     }
  42.  
  43.     if (netto > brutto)
  44.         cout << Fehlercode[2] << endl;
  45.     else
  46.         cout << Fehlercode[0] << endl;
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement