• 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?
 
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  );
0
 
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.
0
 
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
0
Simple Misconfiguration =Network Vulnerability

In this technical webinar, AlgoSec will present several examples of common misconfigurations; including a basic device change, business application connectivity changes, and data center migrations. Learn best practices to protect your business from attack.

 
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.
0
 
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.
0
 
rockiroadsCommented:
Your question that needs rewording, I suggest you post it here
0
 
rockiroadsCommented:
Paul, sorry if I sounded harsh, I didnt mean to. I guess Im not so good at explaining :(

0
 
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
0
 
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
0
 
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
0
 
grg99Commented:
Please read both of my comments.

0
 
pdhazAuthor Commented:
grg99

thanks for the help you had provided,i appreciated it


pdhaz
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.