H
hellfire
Below is a pretty usless progam but being a begginer
and working form a book i need some one to comment
on it IE: is it set out right easy to follow i tried
to use every thing i know to data your comments will
be appricated thanks for your time
/* VB1.C PROGRAM JUST TO MAKE DESISIONS */
#include<stdio.h>
/* DECLARE VARIABLES */
char line[3];
char sex;
char choice;
/* DECLARE FUNCTION PROTOTYPES */
void get_line(void);
void get_sex(void);
void get_choice(void);
int main(void)
{
printf("Enter m for male f for female: ");
get_sex();
if(sex == 'm')
{
printf("are you a master y for yes n for no; ");
get_choice();
if(choice == 'y')
printf("you are a Master:\n");
else
printf("You are a Mr:\n");
}
else if(sex == 'f')
{
printf("are you a miss y for yes n for no: ");
get_choice();
if(choice == 'y')
printf("You are a Miss:\n");
else
printf("You are a Mrs:\n");
}
return 0;
}
/* FUNCTION DEFINITIONS */
void get_line(void)
{
fgets(line, sizeof(line),stdin);
}
void get_sex(void)
{
get_line();
sscanf(line, "%c", &sex);
while(sex != 'm' && sex != 'f' )
{
printf("%c Not a valid entery try again:",sex);
get_line();
sscanf(line, "%c", &sex);
}
}
void get_choice(void)
{
get_line();
sscanf(line, "%c", &choice);
while(choice != 'y' && choice != 'n' )
{
printf("%c Not a valid entery try again:",choice);
get_line();
sscanf(line, "%c", &choice);
}
}
and working form a book i need some one to comment
on it IE: is it set out right easy to follow i tried
to use every thing i know to data your comments will
be appricated thanks for your time
/* VB1.C PROGRAM JUST TO MAKE DESISIONS */
#include<stdio.h>
/* DECLARE VARIABLES */
char line[3];
char sex;
char choice;
/* DECLARE FUNCTION PROTOTYPES */
void get_line(void);
void get_sex(void);
void get_choice(void);
int main(void)
{
printf("Enter m for male f for female: ");
get_sex();
if(sex == 'm')
{
printf("are you a master y for yes n for no; ");
get_choice();
if(choice == 'y')
printf("you are a Master:\n");
else
printf("You are a Mr:\n");
}
else if(sex == 'f')
{
printf("are you a miss y for yes n for no: ");
get_choice();
if(choice == 'y')
printf("You are a Miss:\n");
else
printf("You are a Mrs:\n");
}
return 0;
}
/* FUNCTION DEFINITIONS */
void get_line(void)
{
fgets(line, sizeof(line),stdin);
}
void get_sex(void)
{
get_line();
sscanf(line, "%c", &sex);
while(sex != 'm' && sex != 'f' )
{
printf("%c Not a valid entery try again:",sex);
get_line();
sscanf(line, "%c", &sex);
}
}
void get_choice(void)
{
get_line();
sscanf(line, "%c", &choice);
while(choice != 'y' && choice != 'n' )
{
printf("%c Not a valid entery try again:",choice);
get_line();
sscanf(line, "%c", &choice);
}
}