SSL Certificate
  • Write a C program that prompts the user to enter some information about up to ten individuals
Write a C program that prompts the user to enter some information about up to ten individuals (think of a way to welcome and prompt the user).  It should  store this information in a structure. The program should obtain the information from the structure, and output it as shown in sample run below.
 
Your program should include a structure with a tag name of: “information”.  It should contain the following data as members:
 
a character array to store person's name, defined as:                 name[35]
a character array to store person's street address, defined as: address[50]
a character array to store person's city, defined as:                    city[25]
a character array to store person's state, defined as:                 state[3]
a long integer variable to store person's zip code, defined as:  zip_code
an integer variable to store person's age, defined as:                age
a character variable to store person's gender, defined as:        gender
 
You need to define an array of type: struct information. 
You can call this array: clients[10]. 
 
The dialog with the user must be as follows:
 
         
Whatever Title you want Here including a
“How many prompt” etc.
 
Enter name: Minnie Mouse
Enter street address: 100 Disney Drive
Enter city: Orlando
Enter state: FL
Enter zip code: 99990
Enter age: 25
Enter gender (M or F): F
 
Enter name: Big Bird
Enter street address: 10 Sesame Street
Enter city: Funtown
Enter state: MA
Enter zip code: 01222
Enter age: 20
Enter gender (M or F): m
 
The information you entered is: 
 
Minnie Mouse
100 Disney Drive
Orlando, FL 99990
She is 25 years old.
 
Big Bird
10 Sesame Street
Funtown, MA 01222
He is 20 years old.
 
Note: The coral text represents the "output" from your program and is shown for clarity only here. It is not required that your output be in this color. (Do not even attempt to try!). Also note that what the user types in is indicated by the blue area above. Again, for clarity only. The red is text that you should personalize for yourself.  I also did not show examples of data validation – which you can handle in your own way.
 
Hints/other requirements:
Use gets (or safer_gets() ) instead of scanf or gets() to read in more than one word at a time. (Needed for "name" , "address" and "city", in this program.)
 
Call fflush(stdin);   after any scanf (or getchar) for gender. This will remove any extraneous characters (like carriage returns) from the input buffer. 
 
Structure member state is a 3 element array, not 2. In this field you will be storing a 2 character abbreviation of a state. We need to define the extra (3rd) element to hold the null terminator character. (An optional feature could be to make it capital letters)
 
You should use %di (instead of %li) as the format specifier for the "zip code" because if you enter your zip code starting with the number 0 (zero), C will interpret that number as "octal", which will cause erroneous results. For this reason, I recommend that you use %ld in the scanf statement when prompting the user for the zip code.
 
The above hint handles the zip code as it is being input using a scanf statement. You have a different problem when you want to output the zip code using a printf statement. C does not store leading zeros.So, if the user in fact enters a zip code starting with a zero, you need to do some extra formatting when you output the zip code to display leading zeros if any. We have not yet covered this, so I will give you the solution. You have 2 choices: Either: %.5ld or %05ld. Both of those output format specifiers indicate that you want C to reserve 5 spaces for the output, and if the integer value is less than 5 digits, to pad the integer with leading zeros.
 
You do not need to use user-defined functions or string functions in this program (however, feel free to if you'd like to).
 
You do not need to use pointers in this program. (That will be in another assignment!)
 
Gender should be entered as either M or m for male, or F or f for female, or accept a blank space. Your program should test for "M"ale or "F"emale gender to determine whether to output the age as: He is... or She is... (refer to sample output below for more info.) Remember to test for both uppercase, and lowercase values of M and F or blank is allowed. For example, the user may enter "m" or "M" as the gender, in either case, your program should interpret it as male. (If blank is entered for gender, your program should display only “Age is”.)
 
You need to perform error checking on the age user input (between 1 and 120, hey who knows?), on the gender (blank or m or f, capital or small letters), and zipcode (00001 to 99999).  
 
Excellent Answer
=================
*Instant Download

Write a review

Please login or register to review

Write a C program that prompts the user to enter some information about up to ten individuals

  • $9.99


*All your data are SECURED & ENCRYPTED using a valid, trusted server certificate (Comodo SSL) and we don't store credit card information on our servers and all Payments are SECURED & handled by Paypal.
SSL CertificatePaypal

Tags: c, programming, structure