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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
void getInfo(char street[], char city[], char state[], char zip[]);
void displayAddress(char address[], int numItems);
int main()
{
char street[30] = {'\0'};
char city[20] = {'\0'};
char state[3] = {'\0'};
char zip[6] = {'\0'};
char address[60] = {'\0'};
char runAgain;
do{
getInfo(street, city, state, zip);
strcat(address, street);
strcat(address, ", ");
strcat(address, city);
strcat(address, ", ");
strcat(address, state);
strcat(address, " ");
strcat(address, zip);
cout << "\n\n";
displayAddress(address, 60);
cout << "Would you like to run the program again (Y/N)? ";
cin >> runAgain;
cout << '\n';
} while ((runAgain == 'Y') || (runAgain == 'y'));
return 0;
}
//----------------------------------------------------------------------
void getInfo(char street[], char city[], char state[], char zip[])
{
cout << "Enter your street address: ";
cin.getline(street, 30);
cout << "Enter your city: ";
cin.getline(city, 20);
cout << "Enter your state (2 digits): ";
cin.getline(state, 3);
cout << "Enter your 5-digit zip code: ";
cin.getline(zip, 6);
}
//----------------------------------------------------------------------
void displayAddress(char address[], int numItems)
{
cout << "Your full address is:\n\n";
for (int i = 0; i < strlen( address ); i++)
{
cout << address[i];
}
cout << "\n\n";
}
//----------------------------------------------------------------------
|