Advertisement
Sclafus

array of structs

Mar 8th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. #include <ctime>
  5. using namespace std;
  6.  
  7. const int N = 3;
  8. const int PREZZO_MAX = 200;
  9.  
  10. struct Tipolibro {
  11.     string titolo;
  12.     string autore;
  13.     int anno_di_edizione;
  14.     int prezzo;
  15. };
  16.  
  17. int main(){
  18.     srand (time(NULL));
  19.     Tipolibro Type;
  20.     Tipolibro libri[N] = {}; //array di libri Tipolibro
  21.     int prezzi[N] = {};
  22.     int anni_ed[N] = {};
  23.     int somma_prezzi = 0;
  24.  
  25.     //riempio l'array dei libri
  26.     for (int i = 0; i < N; i++){
  27.         cout << "Inserire titolo libro: ";
  28.         cin >> Type.titolo;
  29.         // cout << "TITOLO: " << Type.titolo << endl; //debug
  30.  
  31.         cout << "Inserire autore libro: ";
  32.         cin >> Type.autore;
  33.         // cout << "AUTORE: " << Type.autore << endl; //debug
  34.  
  35.         cout << "Inserire anno di edizione libro: ";
  36.         cin >> Type.anno_di_edizione;
  37.         // cout << "ANNO: " << Type.anno_di_edizione << endl; //debug
  38.  
  39.         int prezzo_random = rand()%PREZZO_MAX;
  40.         Type.prezzo = prezzo_random;
  41.         cout << "PREZZO: " << Type.prezzo << endl; //debug
  42.         libri[i] = Type;
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement