My first "real" C program needs some help. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

My first "real" C program needs some help.

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

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

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


percentageIncrease = price + price/100;


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

finalPrice = percentageIncrease;

printf("Your final price is %.2lf
", &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.

Comments

  • DonotaloDonotalo Posts: 715Member
    [purple]
    u r calculating [blue]percentageIncrease[/blue] [b]before[/b] taking input. and probably ur calculation of [blue]finalPrice[/blue] is wrong. also, [blue]printf()[/blue] doesnt require [red]&[/red]. here is what it shud be i think:
    [/purple][code]
    : #include
    : #include
    :
    : int main()
    : {
    : double price;
    : double finalPrice;
    : double percentageIncrease;
    : double x;
    :
    : printf("Please enter the cost of your item.
    ");
    : scanf("%lf", &price);

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

    : finalPrice = (price/100)*percentageIncrease;
    :
    : printf("Your final price is %.2lf
    ", finalPrice);
    :
    : system("PAUSE");
    : return 0;
    :
    : }
    [/code]
    [hr][purple]~Donotalo()[/purple]

  • RadiationXRadiationX Posts: 6Member
    : [purple]
    : u r calculating [blue]percentageIncrease[/blue] [b]before[/b] taking input. and probably ur calculation of [blue]finalPrice[/blue] is wrong. also, [blue]printf()[/blue] doesnt require [red]&[/red]. here is what it shud be i think:
    : [/purple][code]
    : : #include
    : : #include
    : :
    : : int main()
    : : {
    : : double price;
    : : double finalPrice;
    : : double percentageIncrease;
    : : double x;
    : :
    : : printf("Please enter the cost of your item.
    ");
    : : scanf("%lf", &price);
    :
    : printf("Please enter the percent markup of your item
    ");
    : : scanf("%lf", &percentageIncrease);
    :
    : : finalPrice = (price/100)*percentageIncrease;
    : :
    : : printf("Your final price is %.2lf
    ", finalPrice);
    : :
    : : system("PAUSE");
    : : return 0;
    : :
    : : }
    : [/code]
    : [hr][purple]~Donotalo()[/purple]
    :
    :
    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.
Sign In or Register to comment.