Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5430
Number of posts: 16951

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
My first "real" C program needs some help. Posted by RadiationX on 19 Jan 2006 at 11:40 AM
Here is the problem i've been given:Write a program that accepts two doubles, representing the cost price (c) and percent markup (m) of an item, and calculates and displays the selling price (s).

Here is the code if written so far to complete this progect. By the way I'm using the free BloodShed compiler version 4.01.

#include <stdio.h>
#include <stdlib.h>

int main()
{
double price;
double finalPrice;
double percentageIncrease;
double x;

printf("Please enter the cost of your item.\n");
scanf("%lf", &price);


percentageIncrease = price + price/100;


printf("Please enter the percent markup of your item\n");
scanf("%lf", &percentageIncrease);

finalPrice = percentageIncrease;

printf("Your final price is %.2lf\n", &finalPrice);

system("PAUSE");
return 0;

}

can anyone suggest what i'm doing wrong? This program compiles with no errors, but it does not produce the correct output. I think that my problem is with the "%lf". any suggestions? For additional info on this project and to see a working example please visit this link :

www.difranco.net/cop2220/homework/hw_2006s.htm

My project is HW01. The .exe is not a virus - i swear. This is due tonight at midnight.
Report
Re: My first "real" C program needs some help. Posted by Donotalo on 19 Jan 2006 at 11:51 AM

u r calculating percentageIncrease before taking input. and probably ur calculation of finalPrice is wrong. also, printf() doesnt require &. here is what it shud be i think:
: #include <stdio.h>
: #include <stdlib.h>
: 
: int main()
: {
:  double price;
:  double finalPrice;
:  double percentageIncrease; 
:  double x;
:  
:         printf("Please enter the cost of your item.\n");
:         scanf("%lf", &price);

          printf("Please enter the percent markup of your item\n");
:         scanf("%lf", &percentageIncrease);

:         finalPrice = (price/100)*percentageIncrease;
:         
:         printf("Your final price is %.2lf\n", finalPrice);
: 
:       system("PAUSE");
:       return 0;
: 
: }


~Donotalo()

Report
Re: My first "real" C program needs some help. Posted by RadiationX on 19 Jan 2006 at 1:21 PM
:
: u r calculating percentageIncrease before taking input. and probably ur calculation of finalPrice is wrong. also, printf() doesnt require &. here is what it shud be i think:
:
: : #include <stdio.h>
: : #include <stdlib.h>
: : 
: : int main()
: : {
: :  double price;
: :  double finalPrice;
: :  double percentageIncrease; 
: :  double x;
: :  
: :         printf("Please enter the cost of your item.\n");
: :         scanf("%lf", &price);
: 
:           printf("Please enter the percent markup of your item\n");
: :         scanf("%lf", &percentageIncrease);
: 
: :         finalPrice = (price/100)*percentageIncrease;
: :         
: :         printf("Your final price is %.2lf\n", finalPrice);
: : 
: :       system("PAUSE");
: :       return 0;
: : 
: : }
: 

:
~Donotalo()
:
:
Dude you did it!I only had to make one correction: finalPrice=(price/100*percentageIncrease +price);
Other than that it's all you. Thank you.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.