Advertisement
Emanuele_Bruno

Esercizio 5

Dec 3rd, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. string Genera(int intero)
  7. {
  8.     int i=0;
  9.     string vocale;
  10.     // bool moneta;
  11.     while (i<intero)
  12.     {
  13.         if (rand()%2) // se esce testa allora -> a , o; se esce croce allora -> e , i , u
  14.         {
  15.             if (rand()%2) // 'a' oppure 'o'
  16.             vocale+='a';
  17.             else
  18.             vocale+='o';
  19.         }
  20.         else
  21.             switch(rand()%3) // 'e' oppure 'i' oppure 'u'
  22.             {
  23.                 case 0:
  24.                     vocale+='e';
  25.                     break;
  26.                 case 1:
  27.                     vocale+='i';
  28.                     break;
  29.                 case 2:
  30.                     vocale+='u';
  31.                     break;
  32.             }
  33.         i++;
  34.     }
  35.     return (vocale);
  36. }
  37.  
  38. int main()
  39. {
  40.     int lanci;
  41.     cout << "Dimmi quante volte lanciare la moneta :";
  42.     cin >> lanci;
  43.     cout << "Questa e' la stringa generata : " << Genera(lanci);
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement