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

?The instructions are at the top for the assignment and what I have so far is wh

ID: 3914779 • Letter: #

Question

?The instructions are at the top for the assignment and what I have so far is what follows. Look over my code and fix any errors please and add things I have missed. I have a lot of errors. Thanks!

Create a Code Blocks project named Strings. Create a function as follows: void askForName( char preface[]. char result[] );

This function can be used as follows: char res[100]; askForName( "Enter your first name:", res ); <-- calling this should give you

Enter your first name: Rick

Now, use this function twice, once for asking fist name and once for asking last name. Concatenate both strings into the full name. Display the first, last, whole names; the show the string length for all three strings.

Next, ask user to enter a state. If the state is Alaska or Florida then use a printf to say that is cold or that is hot. Create a Code Blocks program named DataStructs. You will need to create a data structure named ContactInfo. Declare a global instance of ContactInfo. Create a function that asks the user for contact information. Create a function that shows user information.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void askForName(char preface[], char result[]) {
printf("%s:", preface);
scanf("%s", result);
}

struct ContactInfo {
char fname[100], lname[100];
char address[150];
char city[50], state[50], zip[50];
};
struct ContactInfo ci;

void getContactinfo() {
printf("First Name:");
scanf("%s", ci.fname);
printf("Last Name:");
scanf("%s", ci.lname);
printf("Address:");
scanf("%s", ci.address);
printf("City:");
scanf("%s", ci.city);
printf("State:");
scanf("%s", ci.state);
printf("Zip:");
scanf("%s", ci.zip);

void showContactInfo() printf("First Name:%s ", ci.fname);
printf("Last Name:%s ", ci.lname);
printf("Address:%s ", ci.address);
printf("City:%s ", ci.city);
printf("State:%s " ci.state);
printf("Zip:%s ", ci.zip);
}
int main()
{
char fname[100], lname[100], fullname[150];

askForName("What is your first name?", fname);
askForName("What is your last name?", lname);
strcpy(fullname, fname);
strcat(fullname, " ");
strcat(fullname, lname);

printf("First:%s ", fname, strlen(fname));
printf("Last:%s ", lname, strlen(lname));
printf("Full:%s ", fullname, strlen(fullname));

printf("Enter a State[Alaska OR Florida]?:");
scanf("%s",State);
if(!strcmp(State,"Alaska")){//Check for state if matched
printf("It is cold place ");
flag=0;
}
else if(!strcmp(State,"Florida")){
printf("It is hot place ");
flag=0;
}
else{
printf("Incorrect Entry ");
}
}
} printf("What state are you in ?");
scanf("%s", state);
if( stricmp(state, "florida")==0||
( stricmp(state, "florida")==0||
( stricmp(state, "florida")==0||
( stricmp(state, "florida")==0||

return 0;
}

Explanation / Answer

The corrected code is

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void askForName(char preface[], char result[]) {
printf("%s:", preface);
scanf("%s", result);
}

struct ContactInfo {
char fname[100], lname[100];
char address[150];
char city[50], state[50], zip[50];
};
struct ContactInfo ci;

void getContactinfo()
{
printf("First Name:");
scanf("%s", ci.fname);
printf("Last Name:");
scanf("%s", ci.lname);
printf("Address:");
scanf("%s", ci.address);
printf("City:");
scanf("%s", ci.city);
printf("State:");
scanf("%s", ci.state);
printf("Zip:");
scanf("%s", ci.zip);
}
void showContactInfo()
{
printf("First Name:%s ", ci.fname);
printf("Last Name:%s ", ci.lname);
printf("Address:%s ", ci.address);
printf("City:%s ", ci.city);
printf("State:%s ",ci.state);
printf("Zip:%s ", ci.zip);
}
int main()
{
char fname[100], lname[100], fullname[150];
askForName("What is your first name?", fname);
askForName("What is your last name?", lname);
strcpy(fullname, fname);
strcat(fullname, " ");
strcat(fullname, lname);

printf("First:%s ", fname, strlen(fname));
printf("Last:%s ", lname, strlen(lname));
printf("Full:%s ", fullname, strlen(fullname));

printf("Enter a State[Alaska OR Florida]?:");
scanf("%s",ci.state);
if(!strcmp(ci.state,"Alaska")){//Check for state if matched
printf("It is cold place ");
}
else if(!strcmp(ci.state,"Florida")){
printf("It is hot place ");
}
else{
printf("Incorrect Entry ");
}
return 0;
}

Do give a thumbs up

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