• C

program help

here is my dilema, i have just started in c programming. in the program original format it worked, there was no input required from the user, but now the user must enter an amount and the program does the calculations outputting an answer.
this is where i cannot get it to happen, if i were to take each secton seperately it would work but having them perform in soem type of loop it does not. i have tried to use the if/else statements (which in my thinking it should work, using that format) but i still get errors or some wierd numbers for output or each section just gives me zeros. it seems that the program does not want to perform the required calculations once the user inputs an amount.

thanks for the help

pdhaz



#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.

grg99Commented:
You have the common problem-- not reading the \n or Enter key.  Add a \n to the end of all your scanf's()

Also it will help if you print out the numbers you've just read in.

Not to mention, check the return value from scanf-- it should be "1" if it succeeded in reading in a value.
hiteshgupta1Commented:
U r Trying to print the value of the variable "total sales"
But tas such there is no such varialbe declared in the program
u have three variable for sales
total_sales_a,total_sales_b,total_sales_c
u should print these value as final outcome
grg99Commented:
oh yes, the lines like:   printf("\nthe value of DelMar is\n%.2f, total sales\n")


should be more like:  printf(  "\nthe value of DelMar is %.2f\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
Virus Depot: Cyber Crime Becomes Big Business

The rising threat of malware-as-a-service is not one to be overlooked. Malware-as-a-service is growing and easily purchased from a full-service cyber-criminal store in a “Virus Depot” fashion. View our webinar recording to learn how to best defend against these attacks!

rockiroadsCommented:
question for pdhaz, did u not check any of the answers provided in your original post to this same question? was they wrong, there was no feedback.
pdhazAuthor Commented:
to rockiroads at this point in time i am or was unable to check if they would work, i will do that once i get home from work this evening.
rockiroadsCommented:
Your question that needs rewording, I suggest you post it here
rockiroadsCommented:
Paul, sorry if I sounded harsh, I didnt mean to. I guess Im not so good at explaining :(

PaulCaswellCommented:
rockiroads,

No probs. It is difficult in this environment to get kindness across.

Take a peek here. Its a recent sore point for me.

http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_21794532.html#16349002

I may have implied you were doing wrong, for that I apologise. That is far from my belief.

Paul
pdhazAuthor Commented:
paul,  i understand it will not happen again. i thought that i could close it out at this point and open it again at the place you had suggested. i originally thought that i did post it in the correct spot


pdhaz
pdhazAuthor Commented:
to grg, i see where i did not enter those line incorrectly, i did what you had suggested, what i am having to do not is after i enter a number i have to hit enter again and the output comes back with some off the wall numbers followed by a bunch of zeros. it does not seems as it is seeing the calculations correctly

thanks for the help to

pdhaz
grg99Commented:
Please read both of my comments.

pdhazAuthor Commented:
grg99

thanks for the help you had provided,i appreciated it


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
C

From novice to tech pro — start learning today.