Guest User

praktikum 6

a guest
Dec 14th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. // Labor63.cpp : Defines the entry point for the console application.
  2. //Sebastian Schwinn und Martin Petter 2k17
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <istream>
  7.  
  8. using namespace std;
  9. char z[100];
  10. bool einlesen();
  11. unsigned int quersumme(char z[]);
  12.  
  13. int main()
  14. {
  15.     int qus;
  16.     cout << "Bitte geben Sie eine grosse Zahl ein: (beenden mit ENTER)" << endl;
  17.     if (einlesen() == true) {
  18.         qus = quersumme(z);
  19.     }
  20.     else
  21.         cout << "fehler" << endl;
  22.     system("pause");
  23.     return 0;
  24. }
  25.  
  26. bool einlesen() {
  27.     unsigned int t = 0, i;
  28.     cin.width(size(z));
  29.     cin >> z;
  30.     for (i = 0; i < size(z); i++) {
  31.         cin.get(z[i]);
  32.         t = z[i];
  33.         if (t > 47 && t < 58)
  34.             continue;
  35.         else
  36.             cin.unget();
  37.     }
  38.     return true;
  39. }
  40.  
  41. unsigned int quersumme(char z[]) {
  42.     unsigned int qs = 0;
  43.     cout << "Die Quersumme von ";
  44.     for (unsigned int i = 0; i < strlen(z); i++) {
  45.         cout << z[i];
  46.         qs += z[i] - 48;
  47.     }
  48.     cout << " ist " << qs << endl;
  49.     if (qs % 9 == 0)
  50.         cout << "Ihre Zahl ist durch 9 teilbar." << endl;
  51.     return qs;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment