Question:
CAN U FIND WHATS WRONG WITH THIS C PROGRAM?
Roger
2011-04-16 15:29:15 UTC
include
# include
# include
# include
# include
#include

#define MAX_LENGTH 100

char firstname[MAX_LENGTH]; /* store the Patient's Name*/
char last_name[MAX_LENGTH]; /* store the Patient's Last Name*/
char nurse_name[MAX_LENGTH]; /*Stores the nurse's Name*/
int age; /* store the Patient's age*/
int option; /*variable to stores the user's option in the menu*/
char appt; /* store the whether the patient has an appointment or not*/
char health_card; /* store whether the patient has a health card or not*/
float cost; /* store the Fees to be charged to the patient*/
int valid_input;

main()
{


system ("color B4");
system("cls");
printf("\t\t\t\t Norman Gardens Health Center\n\n");
printf("\t\t\t\t\tFEES CALCULATION\n\n");

/* Prompt the Nurse/user to enter the patient's First Name and read the value entered*/
printf("Patient First Name: ");
scanf("%s", &firstname);

/* Prompt the Nurse/user to enter the patient's Last Name and read the value entered*/
printf("\nPatient Last Name: ");
scanf("%s", &last_name);

/* Prompt the Nurse/user to enter the patient's age and read the value entered*/
printf("\nPatient Age: ");
scanf("%d", &age);


/* Prompt the Nurse/user to enter the patient's age and read the value entered*/
valid_input = 0;
while( valid_input == 0 ) {
printf("\nDoes the Patient have a Health Card? (Y/N): ");
scanf(" %s", &health_card );
health_card = toupper( health_card );
if((health_card == 'Y') || (health_card == 'N') ) valid_input = 1; /*Validates the User's Input*/
else printf("\n\n\007ERROR: INVALID OPTION\n\n");
}


/* Prompt the Nurse/user to enter the patient's age and read the value entered*/
valid_input = 0;
while( valid_input == 0 ) {
printf("\nDoes the Patient have an appointment? (Y/N): ");
scanf(" %s", &appt );
appt = toupper( appt ); /*Converts the user's input to Capital if it isnt*/
if((appt == 'Y') || (appt == 'N') ) valid_input = 1;
else printf("\n\n\007ERROR: INVALID OPTION\n\n");

}


if(appt = "Y") ERROR MESSAGE IN COMPILER:[Warning] assignment makes integer from pointer without a cast
{
if(age > 60)
{
if(health_card = "Y")
{
cost = 80-(80*70%)

}
else{
cost = 99
}
}
printf("%d", cost);


}
getch();

}


The program worked fine until i inserted the IF statement!! Can u tell me whats wrong. th
Five answers:
The Phlebob
2011-04-16 15:48:52 UTC
Nobody seems to have caught the fact that the error line:



if(appt = "Y") ERROR MESSAGE IN COMPILER:[Warning] assignment makes integer



tries to compare (using the wrong operator) a character with the pointer to the string "Y".



if ( appt == 'Y') /*note the single quotes. */



Hope that helps.
JoelKatz
2011-04-16 22:34:03 UTC
You have *three* bugs in that line:



if(appt = "Y")



First, no variable will ever be equal to a string constant (unless it holds a pointer to the first character of that string constant), and "y" is a string constant. Strings in C are stored as pointers to the first character in the string. And when you compare pointers, that checks if they point to the same place. Since one points to a constant and the other points to a variable, they can't ever point to the same place.



Second, the '=' operator is used for assignment. For comparison, '==' is used.



Third, 'appt' is a character. So why are you comparing it to a string?



Also, this line is broken:

scanf("%s", &firstname);

Since 'firstname' is an array, it's already a pointer. Putting an '&' before it makes it a pointer to a pointer, which is not what you want. You're supposed to pass 'scanf' the address at which it's to store what it reads in, not the address of the address. You can either remove the '&' or use '&firstname[0]'.
coachabower
2011-04-16 22:34:45 UTC
The if statements at the end of your code need double equals, ==, you have it in the one above, but at the end you just have one =,



if(appt //////=////// "Y") ERROR MESSAGE IN COMPILER:[Warning] assignment makes integer from pointer without a cast

{

if(age > 60)

{

if(health_card ///////=////// "Y")







if(appt == "Y") ERROR MESSAGE IN COMPILER:[Warning] assignment makes integer from pointer without a cast

{

if(age > 60)

{

if(health_card == "Y")
anonymous
2011-04-16 22:32:30 UTC
You are missing a double "=" sign in the line:



if(appt = "Y") ERROR MESSAGE



it should be



if(appt == "Y") ERROR MESSAGE
Vaibhav
2011-04-16 23:37:30 UTC
the problem is that your if conditions are wrong


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...