I have a function in my program called BoardingPass which is suppose to print the seat number selected in function AvailableSeats, but I cannot get the right seat number to print when the BoardingPass function is called, please point me in the right direction

if( flag == 5 ) /* flag is incremented until 5 is reached, no more available seats in respective class */
{
/* this is printed when there are no available first class seats */
printf( "No available First Class seats, do you want the lowly Loser Class? \t 1 = yes \t 0 = no" );
scanf( "%i", &response );

if( response )
{
/* this allows user to select a seat in loser class when no first class seats are available */
s = SeatsAvailable(2);
}

else
{
/* this is printed when they don't want to sit in loser class when there are no first class seats available */
printf( "You're screwed, there is another flight in 3 long hours, enjoy the long, long, long wait \n");

s = 0;
break; /* this break was added to go right to close plane when they need to go on another flight */
}
}

if( flag == 5 ) /* flag is incremented until 5 is reached, no more available seats in respective class */
{
/* this is printed when there are no available loser class seats */
printf( "No available Loser Class seats, do you want the Uptight First Class? \t 1 = yes \t \t 0 = no \t" );
scanf( "%i", &response );

if( response )
{
/* this allows user to select a seat in loser class when no first class seats are available */
s = SeatsAvailable(1);
}

else
{
/* this is printed when they don't want to sit in first class when there are no loser class seats available */
printf( "You're screwed, there is another flight in 3 long hours, enjoy the long, long, long wait \n");
s = 0;
break; /* this break was added to go right to close plane when they need to go on another flight */
}
}

The commented line you mention was me trying to fix the problem, my thought process was definitely going down the wrong path, and I forgot to remove the line of code.

11-05-2009

Kennedy

Quote:

Originally Posted by slingerland3g

Also use %d and not %i.

Um, Err? Why would you say such a thing? %i is quite useful! What is your justification? <not antagonistic, but asking for information's sake> There are two camps that I have found: Those that were taught %i and those that were taught %d. I have found that %i is a bit more forgiving with the integral input than %d (%i allows the input 0x44fdd, however, %d sees this as the value 0).

11-10-2009

slingerland3g

Quote:

Originally Posted by Kennedy

Um, Err? Why would you say such a thing? %i is quite useful! What is your justification? <not antagonistic, but asking for information's sake> There are two camps that I have found: Those that were taught %i and those that were taught %d. I have found that %i is a bit more forgiving with the integral input than %d (%i allows the input 0x44fdd, however, %d sees this as the value 0).

I was out of step, this is just my preference and there is functionally no difference in using either %d or %i. It would be nice to know the history of why there are two specifiers, I just happen to use and see %d being the dominant specifier in most cases.

11-10-2009

laserlight

Quote:

Originally Posted by slingerland3g

I was out of step, this is just my preference and there is functionally no difference in using either %d or %i. It would be nice to know the history of why there are two specifiers, I just happen to use and see %d being the dominant specifier in most cases.

I happened to answer this elsewhere recently, but Kennedy effectively gave the same answer: functionally there is a difference.

11-10-2009

slingerland3g

Quote:

Originally Posted by laserlight

I happened to answer this elsewhere recently, but Kennedy effectively gave the same answer: functionally there is a difference.

True, but in this case %d is preferred. Using %i can be dangerous as this will be platform/compiler dependent then if I understand your thinking. From a quick google search on the differences I really could not find any concrete definition. But what you are saying I will make a mental note of this. Simply stating, I have always used %d with no issue....so far!

11-10-2009

laserlight

Quote:

Originally Posted by slingerland3g

Using %i can be dangerous as this will be platform/compiler dependent then if I understand your thinking.

No, it will not, since the syntax rules for integer constants in C is well defined by the C standard.

11-10-2009

slingerland3g

Quote:

Originally Posted by laserlight

No, it will not, since the syntax rules for integer constants in C is well defined by the C standard.

Thanks found the source, in the standards, that address the uses of %i, for hex and octal. Thanks.

If you are not sure on the input type either decimal, hex or octal then go with %i, if you are sure of the input type then go with %d, is my logic on this.