Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I'm a begginer with C++ I was wondering how I would add and store floats for example:

int main(int argc, char *argv[])
{
    float height;
    float length;
    float total;

    cout << "Please enter height: ";
    cin >> height;
    cout << "Please enter length: ";
    cin >> length;

// this is the bit I don't understand

    height*length = total; ?

// how do I store the input as a new float?

    
    system("PAUSE");
    return EXIT_SUCCESS;
}
Posted
Updated 9-Nov-10 5:09am
v3

C++, like almost(?) every programming language, requires that you declare your destination and then assign it a value, like this:

total = height * length;

Your textbook should have made this clear.
 
Share this answer
 
Comments
WurmInfinity 9-Nov-10 11:20am    
Cheers, it works.
Try going the other way: destination = source;
total = height*length;
You have already created a new float top store the result in, called "total". You just need to do it the other way round!
 
Share this answer
 
hi, you just have to invert the formula that you wrote:
this is the correct way:

total=height*length;


so what happens here is that, the height and length's value is multiplied and then is assigned to total or stored in the float variable total. What you wrote above will give you an error because it expects a variable at the left side to be assigned a value.
So you want to store the value in total so the correct way is the one i wrote above.
 
Share this answer
 
v2
Comments
Tarun.K.S 9-Nov-10 11:26am    
oops! someone had already answered it!! when i was writing the answer, there were no replies to the question!
Tarun.K.S 9-Nov-10 11:27am    
only when i refreshed the page that i saw the answers!
WurmInfinity 9-Nov-10 11:48am    
No worries. Its all helpfull :D thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900