Thanks that explains a lot. I remember reading that in the text. I 
can sure tell learning code is not something easily done from a book.
I will see what I can do and let you know if it works. 

--- In [email protected], "John Matthews" <[EMAIL PROTECTED]> wrote:
>
> --- In [email protected], "bo" <meh442004@> wrote:
> >
> > I am still reading up on switches. However your help was greatly 
> > appreciated. I went back and looked at my semicolons and brace 
> > placement. Now my program will run but it doesn't do the math. My 
> > output is
> >  "Your tax is"
> >  "Your total is"
> > 
> > Did I do something wrong with my printf statements? or should I  
have 
> > used a constant instead of a float?
> > 
> > here is the revised code:
> > :
> >      if (iResponse ==1){
> >         printf ("\nYour tax is", "fTax1 * fSales");
> >             printf ("\nYour total is", "fTotal1");
> >             }
> > :
> 
> Good effort, but you need to look up printf and format strings. For
> example, to output the value of int i you might do:
> 
>   printf("value is %d\n", i);
> 
> where the %d, a 'conversion specification', tells the compiler that
> there should be an integer argument (i in this case) whose value 
will
> be converted to a string of decimal digits to replace the %d in the
> output text.
> 
> (If you look at the scanf function, it also uses a format string,
> although the argument corresponding to the %d has to be the address 
of
> an integer where the value will be stored - & is the 'address of'
> operator.)
> 
> To output your float values you can use the %f conversion specifier 
eg.
> 
>   printf("value is %f\n", x * y);
> 
> where x and y are floats. What you have done:
> 
>   printf("tax is ", "x * y");
> 
> is give printf a format string with no conversion specifiers in it, 
so
> the format string is just output as-is. The string argument "x * y" 
is
> 'lost', because it doesn't have a corresponding conversion specifier
> in the format string. (This could have caused the program to crash -
> you were lucky.)
> 
> The x and y inside the "" have no relationship with variables x and 
y
> - they are just letters as far as the compiler is concerned.
> 
> HTH
> 
> John
>


Reply via email to