-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpracticep5.cpp
More file actions
44 lines (37 loc) · 892 Bytes
/
practicep5.cpp
File metadata and controls
44 lines (37 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// #include <iostream>
// using namespace std;
// union Car{
// string name;
// int year;
// double price;
// }myCar;
// int main(){
// cout<<"Enter name: ";
// cin >> myCar.name;
// cout<<"Enter year: ";
// cin >> myCar.year;
// cout<<"Enter price: ";
// cin >> myCar.price;
// cout << "Name: " << myCar.name << endl;
// cout << "Year: " << myCar.year << endl;
// cout << "Price: " << myCar.price << endl;
// };
#include <iostream>
using namespace std;
union Car{
char name[50];
int year;
double price;
};
int main(){
Car myCar;
cout<<"Enter name: ";
cin.get(myCar.name,50);
cout << "Name: " << myCar.name << endl;
cout<<"Enter year: ";
cin >> myCar.year;
cout << "Year: " << myCar.year << endl;
cout<<"Enter price: ";
cin >> myCar.price;
cout << "Price: " << myCar.price << endl;
};