I’m an absolute beginner, of C and programming all together.
I am working with sructs that consists of 2 members(char[] and float).
No problem reading values in and printing them out but,
HOW CAN I ACCESS FLOAT VALUES AND CALCULATE THEIR TOTAL?
I’m an absolute beginner, of C and programming all together.
I am working with sructs that consists of 2 members(char[] and float).
No problem reading values in and printing them out but,
HOW CAN I ACCESS FLOAT VALUES AND CALCULATE THEIR TOTAL?
Something like that.Code:struct buyaCbook { char gonow[ ANDBUYABOOK ]; float learnthebasics; }; ... struct buyaCbook now; now.learnthebasics = 1.0;
Quzah.
Hope is the first step on the road to disappointment.
I had that exact same problem, and your code totally helped me out!
Thanks!
Originally Posted by quzah
Thank you for your help, I really appreciate it, but, unfortunately, it didn’t solve my problem.
When I sad I am a beginner I meant I have not done much coding. I have learnt a bit of theory though, and I’m familiar with accessing members of a struct, name.float and other_name->float. What I need to do is add all the float values to get their total. Values are read in with scanf(), but name.float + other_name.float = float obviously does not work. What am I missing here?
Post some actual code, not a description.
Can you for example add two floats which are not in a structure?
You seem to be doing
v1 + v2 = answer;
What you should have is
answer = v1 + v2;
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
>but name.float + other_name.float = float obviously does not work.
I think u might be well wish to have 2 varaiables of type struct.
Something like this
ssharish2005Code:struct buyaCbook now; struct buyaCbook now1; double res; now.learnthebasics = 1.0; now1.learnthebasics = 2.0; res = now.learnthebasics + now1.learnthebasics;