Store area code,exchange code,number using c++
A phone number can be thought of as having three parts:the area(212),the exchange(767),and the number(8900),write a structure to store three parts of a phone number separately, initialize one,and have the user input a number for the other one.
Area code,Exchange,Number = 416 222 1212
👉When using structure in c++ then using this syntax ,and if we declare variable in structure definition follow this syntax,
coding:
using namespace std;
struct phone
{
int code,exchange,number;
}n1,n2;
int main()
{
n1.code=212;
n1.exchange=767;
n1.number=8900;
cout<<"\n my code is:"<<n1.code<<"\n exchange" <<n1.exchange<<"\n number:"<<n1.number;
cout<<"enter code of our area ,exchange,number\n";
cin>>n2.code>>n2.exchange>>n2.number;
cout<<"\n your new code is:"<<n2.code<<"\n new exchange: "<<n2.exchange<<"\n new number is:"<<n2.number;
return 0;
}
output:
nice work
ReplyDelete