[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

program help

Posted on 2006-04-04
13
Medium Priority
?
249 Views
Last Modified: 2010-04-15
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);
 

}
0
Comment
Question by:pdhaz
  • 4
  • 3
  • 3
  • +2
12 Comments
 
LVL 22

Expert Comment

by:grg99
ID: 16369562
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
 
LVL 8

Expert Comment

by:hiteshgupta1
ID: 16369574
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
 
LVL 22

Accepted Solution

by:
grg99 earned 750 total points
ID: 16369621
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 65

Expert Comment

by:rockiroads
ID: 16371834
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
 

Author Comment

by:pdhaz
ID: 16375336
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
 
LVL 65

Expert Comment

by:rockiroads
ID: 16375366
Your question that needs rewording, I suggest you post it here
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16376364
Paul, sorry if I sounded harsh, I didnt mean to. I guess Im not so good at explaining :(

0
 
LVL 16

Expert Comment

by:PaulCaswell
ID: 16376449
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
 

Author Comment

by:pdhaz
ID: 16377591
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
 

Author Comment

by:pdhaz
ID: 16377679
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
 
LVL 22

Expert Comment

by:grg99
ID: 16380123
Please read both of my comments.

0
 

Author Comment

by:pdhaz
ID: 16397346
grg99

thanks for the help you had provided,i appreciated it


pdhaz
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses
Course of the Month18 days, 17 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question