Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. typedef struct
  4. {
  5.     char tensach[50];
  6.     char tacgia[30];
  7.     union {
  8.         float USD;
  9.         long VND;
  10.     } gia;
  11.     //int VND; //=1 VND,#1 USD
  12.     float giamgia;
  13. } sach;
  14. sach s;
  15. float thanhtien;
  16.  
  17. void thongtinsach(sach s){
  18.     cout << "Ten sach: " << s.tensach << endl;
  19.     cout << "Ten tac gia: " << s.tacgia << endl;
  20.  
  21.     s.giamgia = float(0.3 * s.gia.VND);
  22.     thanhtien = s.gia.VND - s.giamgia;
  23.  
  24.     if (thanhtien == 1)
  25.         cout << "Thanh tien: " << thanhtien << " VND" << endl;
  26.     else
  27.         cout << "Thanh tien: " << thanhtien/20.5 << " USD" << endl;
  28. }
  29.  
  30. int main(){
  31.     cout << "Nhap ten sach: " << endl;
  32.     cin.getline(s.tensach, 50);
  33.     cout << "nhap ten tac gia: " << endl;
  34.     cin.getline(s.tacgia, 30);
  35.     cout << "Nhap gia sach: " << endl;
  36.     cin >> s.gia.VND;
  37.     thongtinsach(s);
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement