Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, I need some C programming help. I am using Visual Studio. My main problem is

ID: 3118941 • Letter: H

Question

Hi, I need some C programming help. I am using Visual Studio. My main problem is how to get user imput for a struct. The instructions are at the the top. Here is what I have:

/*Write a program that creates a structure template with the following data fields.
The program should then prompt the user to enter the data to populate the structure.
Finally, use printf( ) to display the information entered by the user.

Account number
Account owner street address (string)
Account owner city/state (string)
Account owner zip code
Account balances
Account credit limit
Account name*/

#include<stdio.h>
#include<string.h>
#define MAX 100


struct account {//declare struct
   int num;
   char st_addr[MAX];
   char city_state[MAX];
   int zip;
   double balances;
   int cred_lim;
   char name;
};

int main()
{
   struct account info;// declare info as account variable

   printf("Enter account number:");
   scanf("%d ", &info.num);

   printf("Enter account owner street address:");
   gets(info.st_addr);

   printf("Enter account owner city and state:");
   gets(info.city_state);

   printf("Enter account owner zip code:");
   scanf("%d", &info.zip);

   printf("Enter account balances:");
   scanf("%lf", &info.balances);

   printf("Enter account credit limit:");
   scanf("%d", &info.cred_lim);

   printf("Enter account name:");
   scanf("%s", &info.name);
   //finished getting info
  
   //gives info back
   printf("Account number: %d ", info.num);
   printf("Account owner street address: %s ", info.st_addr[MAX]);
   printf("Account owner city / state: %s ", info.city_state[MAX]);
   printf("Account owner zip code: %d ", info.zip);
   printf("Account balances: %d ", info.balances);
   printf("Account credit limit: %d ", info.cred_lim);
   printf("Account name: %s ", info.name);

   return 0;
}

Thank you!

Explanation / Answer

Answer:

#include <stdio.h>
#include <stdlib.h>
void print(char number[],char add[],char cstate[],int zcode,int bal,int climit,char sname[])
{
printf(" ----------------------------- ");
printf("Account number : %s ", number);
printf("Account owner street address: %s ", add);
printf("Account owner city/state : %s ", cstate);
printf("Account owner zip code : %d ", zcode);
printf("Account balances : %d ", bal);
printf("Account credit limit : %d ", climit);
printf("Account name : %s ", sname);
printf("----------------------------- ");
}
struct Emp{
char id_num[6];
char address[100];
char citystate[100];
int zipcode;
int balances;
int creditlimit;
char name[50];
};
  
int main()
{
struct Emp emp_1;
  
printf("Enter Account number: ");
scanf("%s", emp_1.id_num);
printf("Enter Account owner street address: ");
scanf("%s", emp_1.address);
printf("Enter Account owner city/state: ");
scanf("%s", emp_1.citystate);
printf("Enter Account owner zip code: ");
scanf("%d", &emp_1.zipcode);
printf("Enter Account balances: ");
scanf("%d", &emp_1.balances);
printf("Enter Account credit limit: ");
scanf("%d", &emp_1.creditlimit);
printf("Enter Account name: ");
scanf("%s", &emp_1.name);
print(emp_1.id_num,emp_1.address,emp_1.citystate,emp_1.zipcode,emp_1.balances,emp_1.creditlimit,emp_1.name);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote