Hi everyone, I'm a newbie to C/C++ and I need some help with a minor C
program. My assignment is to take two programs and mesh them together. The
1st program I wrote compiles and works fine. The 2nd program is to add to
the 1st program with an if_then_else statement, and it's code is also
correct as well; I just don't know how to or where to put it into the rest
of the 1st program to make it work as one. I've tried to modify it but I
get compiler errors. I look forward to any help some kind soul can provide.
The code with both pieces is below. Thanks, Basil Fawlty of Fawlty Towers
FYI - I'm using Notepad to edit the text and a free C/C++ compiler yanked of
the Internet via Download.com called Digital Mars.
#include <stdio.h>
main()
{
int age;
float weight;
char first[15], last[15]; /* 2 char arrays */
printf("\nWhat is your first name? ");
scanf(" %s", first); /* No ampersand on
character strings */
printf("What is your last name? ");
scanf(" %s", last); /* No apersand on character strings */
printf("How old are you? ");
scanf(" %d", &age); /* Ampersand required */
printf("How do you weight? ");
scanf(" %f", &weight); /* Ampersand required
*/
printf("\nHere is the information you entered:\n");
printf("Name: %s %s\n", first, last);
printf("Weight: %3.0f\n", weight);
printf("Age: %d", age);
if (age < 18)
{ printf("You cannnot vote yet\n");
yrs = 18 - age;
printf("You can vote in d% years.\n",
yrs);
}
else
{
printf("You can vote.\n);
}
return 0; /* Always best to do this */
}