Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. /*Zdefiniuj typ strukturalny oraz 100-elementową tablicę
  2. pozwalającą przechowywać informacje o książkach w bibliotece
  3. (tytuł, autor, indeks, cena) oraz napisz funkcję, która wyświetli na ekranie
  4. wszystkie dane tanich książek (tzn. cena<10zł)*/
  5.  
  6. #include <stdio.h>
  7. #include <conio.h>
  8. #include <cstdlib>
  9.  
  10. struct BOOK
  11. {
  12.     char Title[32];
  13.     char Autor[32];
  14.     int Index;
  15.     double Price;
  16. };
  17.  
  18. void search_cheap_books(BOOK books[]);
  19.  
  20. int main()
  21. {
  22.     BOOK TabBOOK[5]; //HowMany = 100
  23.  
  24.     for(auto Iterator=0; Iterator < 5; Iterator++)
  25.     {
  26.         fseek(stdin, 0, SEEK_END);
  27.         system("cls");
  28.         printf("Podaj tytul ksiazki : ");
  29.         fgets(TabBOOK[Iterator].Title, 32, stdin);
  30.         printf("Podaj autora ksiazki : ");
  31.         fgets(TabBOOK[Iterator].Autor, 32, stdin);
  32.         printf("Podaj cene ksiazki : ");
  33.         scanf("%f", &TabBOOK[Iterator].Price); // Tutaj jest blad, jakis pomysl jak to naprawic ?
  34.  
  35.         TabBOOK[Iterator].Index = Iterator;
  36.     }
  37.  
  38.     search_cheap_books(TabBOOK);
  39.  
  40.     _getch();
  41.     return 0;
  42. }
  43.  
  44. void search_cheap_books(BOOK books[])
  45. {
  46.     system("cls");
  47.     printf("Ksiazki ponizej 10zl to :\n\n");
  48.     for(auto Iterator = 0; Iterator < 5; Iterator++)
  49.     {
  50.         if(books[Iterator].Price <10 )
  51.         {
  52.             printf("Autor %s\n", books[Iterator].Autor);
  53.             printf("Tytul : %s\n", books[Iterator].Title);
  54.             printf("ID ksiazki : %d\n", books[Iterator].Index);
  55.             printf("Cena : %f\n\n", books[Iterator].Price);
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement