if statement in C need help

1 reply [Last post]
jmmuise08
Offline
Last seen: 10 years 3 weeks ago
Joined: 2009-09-06
bOt Points: 54

i'm taking a class and i'm new to programming so i need help.

 

I have to use if statements project put i'm have trouble with it. i would apperacte any help i could get

Here is what i have so far:

 

 

#include <stdio.h> /* Include header to allow use of console functions */
#include <stdlib.h> /* Include header to allow use of system functions */

 

#define ADULT 18 /* Age breakpoint for an adult */
#define SMWD 1000 /* Salary multiplier with degree */
#define SMWO 600 /* Salary multiplier without degree */

 

int main (void){
float AGE; /* Applicant's age */
char DEG; /* College degree status (Y/N) */
double SAL; /*Annual Salary Offer*/
float WHN = ADULT - AGE; /* Annual salary offer */

 

 

system ("cls"); /* Clear the Screen */
printf ("Applicant Screening Program\n\n");
printf ("How old are you?");
scanf ("%f", & AGE);

if (AGE >= ADULT)

printf ("Do you have a college degree (Y/N)?\n\n");
scanf ("%c", & DEG);

else  printf ("\nSorry, you must be %d or older for this job.\n", ADULT);
 printf ("\nPlease apply again in %f years.\n", WHN);

if (DEG == 'Y' || DEG == 'y')
 SAL = AGE * SMWD;

else SAL = AGE * SMWO;
printf ("You qualify!");
printf ("Your annual salary would be $%8.2f.\n", SAL);
printf ("See our staff for an application.");

return (0); /* Send a null error code to the parent process */
}

robo.genius
Offline
Last seen: 6 years 11 weeks ago
Joined: 2009-04-12
bOt Points: 265
hi jmmuise08, you have not

hi jmmuise08,

you have not used curly brackets for enclosing multiple statements in if else condition. check out the code below -

#include <stdio.h> /* Include header to allow use of console functions */
#include <stdlib.h> /* Include header to allow use of system functions */

 

#define ADULT 18 /* Age breakpoint for an adult */
#define SMWD 1000 /* Salary multiplier with degree */
#define SMWO 600 /* Salary multiplier without degree */

 

int main (void){
float AGE; /* Applicant's age */
char DEG; /* College degree status (Y/N) */
double SAL; /*Annual Salary Offer*/
float WHN = ADULT - AGE; /* Annual salary offer */

 

 

system ("cls"); /* Clear the Screen */
printf ("Applicant Screening Program\n\n");
printf ("How old are you?");
scanf ("%f", & AGE);

if (AGE >= ADULT){

printf ("Do you have a college degree (Y/N)?\n\n");
scanf ("%c", & DEG);
}

else  {
printf ("\nSorry, you must be %d or older for this job.\n", ADULT);
printf ("\nPlease apply again in %f years.\n", WHN);
exit(0);

}

if (DEG == 'Y' || DEG == 'y')
 SAL = AGE * SMWD;

else SAL = AGE * SMWO;
printf ("You qualify!");
printf ("Your annual salary would be $%8.2f.\n", SAL);
printf ("See our staff for an application.");

return (0); /* Send a null error code to the parent process */
}

 

i have highlighted the corrections.