Jump to content

I'm having trouble using std::fixed

Chasem121
Go to solution Solved by Nineshadow,

I think this is your problem :

amountPercentage == amountCookies/48;.... == ... ;... == ... ;

You aren't setting those values at all. That's why they're 0.

Whenever I include std::fixed, it makes all my variables output as 0.00.

I'm not sure how to format the code into the forum like some others do, if someone can explain that I will do it. Until then, here's an image of it.

3t3ETJh.png

Link to comment
Share on other sites

Link to post
Share on other sites

I think this is your problem :

amountPercentage == amountCookies/48;.... == ... ;... == ... ;

You aren't setting those values at all. That's why they're 0.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

[code]Code inside here[/code]

ah thanks

#include <iostream>#include <iomanip>using namespace std;int main (){    //declaring variables    double amountCookies;    double amountFlour;    double amountSugar;    double amountButter;    double servPercentage;        //getting input needed    cout << "Please input the amount of cookies you wish to make \n";    cin >> amountCookies;        //running formulas    servPercentage == amountCookies / 48;    amountFlour == servPercentage * 2.5;    amountSugar == servPercentage * 1.75;    amountButter ==  servPercentage * 1;        //outputting required amounts of ingredients    cout << "You need,\n" << fixed << setprecision(2) << amountFlour << " cups of Flour, \n"<< amountSugar << " cups of Sugar and \n" << amountButter << " cups of Butter" << endl;        return 0;}
Link to comment
Share on other sites

Link to post
Share on other sites

I think this is your problem :

amountPercentage == amountCookies/48;.... == ... ;... == ... ;

You aren't setting those values at all. That's why they're 0.

Shit, figures it was something stupid. Thanks

Link to comment
Share on other sites

Link to post
Share on other sites


#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

double amountCookies;

double amountFlour;

double amountSugar;

double amountButter;

double servPercentage;

cout << "Please inupt the number of cookies you want to make : \n";

cin >> amountCookies;

servPercentage = amountCookies/48;

amountFlour = servPercentage * 2.5;

amountSugar = servPercentage * 1.75;

amountButter = servPercentage;

cout << "You need :\n" << fixed << setprecision(2) << amountFlour << " cups of flour\n"<< amountSugar << " cups of sugar \n" << amountButter << " cups of butter\n";

return 0;

}

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×