Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     string input;
  9.     int jumlahInput = 1;
  10.  
  11.     cout << "Masukkan Input : ";
  12.     getline(cin, input);
  13.  
  14.     if (input[0] == '0')
  15.     {
  16.         cout << "Angka pertama tidak boleh nol";
  17.         return 0;
  18.     }
  19.  
  20.     for (int i = 0; i < input.length(); i++)
  21.     {
  22.         if (input[i] == ' ')
  23.         {
  24.             jumlahInput++;
  25.             if (jumlahInput > 3)
  26.             {
  27.                 cout << "Jumlah input maximal 3";
  28.                 return 0;
  29.             }
  30.         }
  31.     }
  32.     cout << jumlahInput;
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement