help in c programming

here is my dilema, i have just started in c programming and in my program it needs to perform some caluclations which they currently they do not. i have tried several formats to get this to work bu to no avail.
i have tried using the if/else statements but it does not work and i am unsure if i am performing the structure correctly.
the below is a copy of the program if i could receive some guidance it would be most appreciated


#include <stdio.h>                    
#include <math.h>
 
int main()
 
{
float taxa, taxb, taxc;              
float total_sales_a, total_sales_b, total_sales_c;
float purchase_amounta, purchase_amountb, purchase_amountc;          
                               
printf("KUBLER FINE FOODS\n");
 
printf("\nDelMar\n");  
printf("\nenter purchase amount\n");    
scanf("%f",&purchase_amounta);
taxa=purchase_amounta*.0725;        
total_sales_a=purchase_amounta+taxa;  
printf("\nthe value of DelMar is\n%.2f, total sales\n");  
 
printf("\nEncinitas\n");
printf("\nenter purchase amount\n");
scanf("%f",&purchase_amountb);
taxb=purchase_amountb*.0725;
total_sales_b=purchase_amountb+taxb;        
printf("\nthe value of Encintas is\n%.2f, total sales\n");
 
printf("\nLaJolla\n");
printf("\nenter purchase amount\n");
scanf("%f",&purchase_amountc);
taxc=purchase_amountc*.0775;
total_sales_c=purchase_amountc+taxc;
printf("\nthe value of LaJolla is\n%.2f, total sales\n");
 
return (0);
 

}
 
pdhazAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rockiroadsCommented:
Trying to remember my C, its been a while

in Printf, when u want to print a variable

printf("\nthe value of DelMar is\n%.2f, total sales\n");

where is your variable? should it be like this

printf("\nthe value of DelMar is\n%.2f, total sales\n", total_sales_a);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PaulCaswellCommented:
Hi pdhaz,

There's actually a page at EE for C questions. Would you like me to move this question there form you?

I think your problem is here (and the other two places you do it:

printf("\nthe value of DelMar is\n%.2f, total sales\n");  

By using the '%.2f' in the format you are asking printf to take the next parameter in the brackets and format it as a float. You havent put inaything for the next parameter. You probably meant:

printf("\nthe value of DelMar is\n%.2f, total sales\n",total_sales_a);  

Paul
PaulCaswellCommented:
Hi pdhaz,

Here's the 'C' pages for your next C question :-)

http://www.experts-exchange.com/Programming/Programming_Languages/C/

Paul
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

pdhazAuthor Commented:
thanks paul, for the advice i have just submitted the question in that section
rockiroadsCommented:
Note for pdhaz,

Im not being rude, not moaning about points or anything

But, in the interests of people reading this post in trying to find solutions

Was the answer to your solution a link provided by Paul?

Did u try any of the suggestions by myself or Paul? Were they wrong or right.

Just general feedback please.
pdhazAuthor Commented:
to rockiroads, i apologize, i responded when i woke up first thing this morning and i realized that i had worded my question wrong. in the program in the original format i had gotten it to work, but the question i should have asked was that i wanted the program to allow input from the keyboard, perform the given claculations and output an answer. i need this to be done for all three, once i get an answer from one then the next one should ask someone to input some numbers respond with an aswer then goto the third and finish. that is what i should have worded the question.
again i am sorry for the misunderstanding


pdhaz
rockiroadsCommented:
No worries pdhaz, its good to have clarification for others who read this post, that is all. Thanks for responding.
pdhazAuthor Commented:
paul that change would be great.

to rockiroads i had tried that change and another that was suggested by grg from the other post. now what i get after i enter those changes is when i eneter a number i have to hit enter and enter again then in return i get an off the wall number followed by a bunch of zeros. it does not seem that the calculations are performing.

again thanks for the help , i did not mena to cause so much trouble.

pdhaz
pdhazAuthor Commented:
rockiroads when i moved all the equations to the bottom of the program it seem to take care of all those funky numbers but still it does not perform any of the calculations


pdhaz
rockiroadsCommented:
pdhaz, pls dont take offence. I only wanted to get this correct for other readers. Points is not the issue

ok, going back to your code, Unless u got a decent debugger, just write diagnostics e.g.

      scanf("%f",&purchase_amounta);

      print ("DIAG: Purchase Amount %f\n", purchase_amounta);

      taxa=purchase_amounta*.0725;        

      print ("DIAG: TaxA %f\n", taxa);

Then follow it through, dump for all variables where you think its not working
You will then be able to see where it may be going wrong, or what values are not set

I have not seen your reworked code so if u post that, I will be able to see better



rockiroadsCommented:
ok, looking at the example code you given, can u just check the printf statements

I dont know if this is a cut/paste error when u posted here or not

u have

total_sales_a=purchase_amounta+taxa;  
printf("\nthe value of DelMar is\n%.2f, total sales\n");  
 
total_sales_b=purchase_amountb+taxb;        
printf("\nthe value of Encintas is\n%.2f, total sales\n");
 
total_sales_c=purchase_amountc+taxc;
printf("\nthe value of LaJolla is\n%.2f, total sales\n");

Note the variable u are printing, should it not be the variable you are setting?
i.e.

printf("\nthe value of DelMar is\n%.2f", total sales_a);  
printf("\nthe value of Encintas is\n%.2f", total sales_b);  
printf("\nthe value of LaJolla is\n%.2f", total sales_c);  

rockiroadsCommented:
Paul, if u was going to reassign points, u should at least split it. I would of preferred a split. Afterall, you gave a explanation which could explain the delay of 1 minute :)
Thanks anyway
PaulCaswellCommented:
rockiroads,

The Page Editor's decision is final.:-) You got the right answer first. Mine therefore just filled in. Thanks for the honesty though.

Paul
rockiroadsCommented:
oh alright then. I best not argue with Page Editor eh
hee! hee! hee!
pdhazAuthor Commented:
to rockiroads here is what i had tried after i inputted the suggestions, also you mentioned if i had a good debugger program where would one get one? right now i have the miracle c compiler (from school)

#include <stdio.h>                    
#include <math.h>
 
int main()
 
{
float taxa, taxb, taxc;              
float total_sales_a, total_sales_b, total_sales_c;
float purchase_amounta, purchase_amountb, purchase_amountc;          
                               
printf("KUBLER FINE FOODS\n");
 
printf("\nDelMar\n");  
printf("\nenter purchase amount\n");
scanf("%f,&purchase_amounta\n");  
printf("\nthe value of DelMar is\n%.2f, total sales\n",total_sales_a);  

printf("\nEncinitas\n");
printf("\nenter purchase amount\n");
scanf("%f,&purchase_amountb\n");
printf("\nthe value of Encintas is\n%.2f, total sales\n",total_sales_b);

printf("\nLaJolla\n");
printf("\nenter purchase amount\n");
scanf("%f,&purchase_amountc,\n");
printf("\nthe value of LaJolla is\n%.2f, total sales\n", total_sales_c);

taxa=purchase_amounta*.0725;        
total_sales_a=purchase_amounta+taxa;
taxb=purchase_amountb*.0725;
total_sales_b=purchase_amountb+taxb;    
taxc=purchase_amountc*.0775;
total_sales_c=purchase_amountc+taxc;
 
return (0);

}  
question, is there a way that you can treat these as individual events? if i were to take only one it would work but not when it involves all three calculations.


thanks

pdhaz
rockiroadsCommented:
you are printing totals before you are calculating

Do your printf's after calculating total_sales
ie.e

taxa=purchase_amounta*.0725;        
total_sales_a=purchase_amounta+taxa;
taxb=purchase_amountb*.0725;
total_sales_b=purchase_amountb+taxb;    
taxc=purchase_amountc*.0775;
total_sales_c=purchase_amountc+taxc

printf("\nthe value of DelMar is\n%.2f, total sales\n",total_sales_a);
printf("\nthe value of Encintas is\n%.2f, total sales\n",total_sales_b);
printf("\nthe value of LaJolla is\n%.2f, total sales\n", total_sales_c);
pdhazAuthor Commented:
i think there may be something wrong with the compiler i have. when i do as you have suggested what i get now is when i punch in a number i have to hit enter twice then the calcualtions appear beneath everything, but they are still non-existent. it still does not want to compute
rockiroadsCommented:
I am flying off to the States now, if and when I manage to get internet access, I will help you with this further.

The other thing, u said, if u take one it works, but not all three.
I dont know why

but u could try a sort of workaround,

create 3 functions, each doing their own prompt and printing the results.
As u say, it works for one

in your main code, call each one individually, see if it works, this will help u trap down any problems if any exist
then try calling two of them and see what happens, then three

pdhazAuthor Commented:
rockiroads

never guess what happen last night, i was tinkering around with the program after i went running and the ole light bulb came on. (i think it had to do with the extra oxygen) but i got it to work. i think there was something wrong with the format or initial code but i went to another one i had done up with only two, i got them to work with your additions and then i just added the third and they came up
/*  kubler fine foods sales tax calulation  */
#include <stdio.h>                    
#include <math.h>
 

int main()
 
{
float  g, h, i;     //int assign to delmar
float  a, b, c;     //int assigned to encintas
float  d, e, f;     //int assinged to lajolla
int idummy;     //to hold program in dos
 

printf("KUBLER FINE FOODS\n");
 
printf("\nDelMar\n");                                          
printf("\nenter purchase amount\n");  
scanf("%f", &g);
h=g*.0725;         //initial calculations
i=g + h;         //final calculations
printf("\nthe purchase price is\n%.2f, total purchase price w/tax\n",i);          //output of purchase price w/tax
 
printf("\nEncintas\n");                                          
printf("\nenter purchase amount\n");  
scanf("%f", &a);
b=a*.075;         //initial calculations
c=a + b;         //final calculations
printf("\nthe purchase price is\n%.2f, total purchase price w/tax\n",c);      //output of purchase price w/tax
 
printf("\nLajolla\n");                                          
printf("\nenter purchase amount\n");  
scanf("%f", &d);
e=d*.07775;         //initial calculations
f=d + e;         //final calculations
printf("\nthe purchase price is\n%.2f, total purchase price w/tax\n",f);      //output of purchase price w/tax
 
return 0;                                                    //i put the return statement here because once i put the scanf for
scanf("i%",idummy);                 // cont. idummy it casued me to hit the enter key twice in order to complete program
 
}
 
as you said i went and did them as seperate functions and they came up. my only problem is my books do not tell me how  to print or input something in dollars/currency, would you be able to provide sooooome guidance with this.
have a good flight and again thanks for all your help!

pdhaz
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.