Help - C++ Assignment Question
Help - C++ Assignment Question
Hi
Please can someone assist me with the ffg. Its a question out of my assignment
Rewrite the following piece of code, correcting all the problems found:
void CalculateValues (const in&a, float *b, int &c)
{
d = 2.04;
if (*a = 0)
*a += 1;
c = a + d;
else
b = c / d;
c = a - b + d;
}
HINT: If a=4, b=0.0 and c=5 when this function is called, their values when this function returns should be: a=4, b=0.25, and c=24.15 (6marks)
Please can someone assist me with the ffg. Its a question out of my assignment
Rewrite the following piece of code, correcting all the problems found:
void CalculateValues (const in&a, float *b, int &c)
{
d = 2.04;
if (*a = 0)
*a += 1;
c = a + d;
else
b = c / d;
c = a - b + d;
}
HINT: If a=4, b=0.0 and c=5 when this function is called, their values when this function returns should be: a=4, b=0.25, and c=24.15 (6marks)
Some time or another you will have to learn...
BTW - What year you finished school in Newcastle? Which school were you in? I matriculated in 2003... Maybe we know each other...
BTW - What year you finished school in Newcastle? Which school were you in? I matriculated in 2003... Maybe we know each other...
My BF2142 Stats:
Slasher : Former member of www.PCFormat.co.za
I have reached the end of my near 5 year forum life. Farewell good days...
slasher (at) webmail (dot) co (dot) za
Slasher : Former member of www.PCFormat.co.za
I have reached the end of my near 5 year forum life. Farewell good days...
slasher (at) webmail (dot) co (dot) za
-
- Registered User
- Posts: 28520
- Joined: 06 Oct 2003, 02:00
- Processor: Intel i5 650
- Motherboard: Asus P7H55-M LX
- Graphics card: Gigabyte 7850 2GB OC
- Memory: 8GB Kingston DDR3
- Location: In my skin
- Contact:
Code: Select all
HAI
CAN HAS STDIO?
D = 2.04;
IZ :(*A = 0:)
*A += 1;
C = A + D;p
NOWAI
B = C / D;p
C = A - B + D;p
KTHNXBAI
"Every thinking man is a drinking man."
Member of the Barberton Tigers
Member of the Barberton Tigers
Start with the fact that d is never defined...
I dont know C++ , cant help you...
Did you read part 2 of my post?
I dont know C++ , cant help you...
Did you read part 2 of my post?
My BF2142 Stats:
Slasher : Former member of www.PCFormat.co.za
I have reached the end of my near 5 year forum life. Farewell good days...
slasher (at) webmail (dot) co (dot) za
Slasher : Former member of www.PCFormat.co.za
I have reached the end of my near 5 year forum life. Farewell good days...
slasher (at) webmail (dot) co (dot) za
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
the errors are glaring for anyone who can manage the 'theory' part...
in c++:
what does '*' and '&' signify?
what happens when you iterate '*'?
how is an if/else evaluated?
really... this is like "intro to programming 101"... simply handing it to you on a plate does you no favours whatsoever... buckle down and do the work.
<for an encore, kicks some puppies into oncomming traffic and smacks ceiling cat with a wiffle bat...>
in c++:
what does '*' and '&' signify?
what happens when you iterate '*'?
how is an if/else evaluated?
really... this is like "intro to programming 101"... simply handing it to you on a plate does you no favours whatsoever... buckle down and do the work.
<for an encore, kicks some puppies into oncomming traffic and smacks ceiling cat with a wiffle bat...>
Last edited by rustypup on 12 Jul 2007, 16:21, edited 1 time in total.
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Research pointers. If you get really desperate, hand in this:
void CalculateValues( int a, float *b, float *c)
{
*b=0.25f;
*c=24.15f;
}
void CalculateValues( int a, float *b, float *c)
{
*b=0.25f;
*c=24.15f;
}
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Firstly, I have done zero programming, my course includes, financial management, business management, business communication, elements of programming and then C++ programming. I dont understand why they would put such a course like this together....
Anyway this is what I know so....
the & is the reference operator and can be read as 'address of'
the * is the dereference operator and can be read as 'value pointed by'
im not sure what happens when you iterate '*'
if/else is evaluated by true/false
Anyway this is what I know so....
the & is the reference operator and can be read as 'address of'
the * is the dereference operator and can be read as 'value pointed by'
im not sure what happens when you iterate '*'
if/else is evaluated by true/false
Code: Select all
void CalculateValues (const int &a, float *b, float &c) { // Correctly define c as a float
float d = 2.04; // Define d before attempting to modify it
if (a == 0) // Remove derefence (*) operator - a is a reference, not a pointer
// And change assignment (=) operator to equality (==) operator
{ // Wrap the block in braces
; // Statement was illegal - a can't be incremented because it is defined const
c = a + d;
} else {
*b = c / d; // Dereference b first - otherwise you'll change the pointer
c = a - (*b) + d; // Dereference b again
}
}
NOTE: I've only fixed the syntax errors - you'll still need to modify it to output the correct values.
'One will rarely err if extreme actions be ascribed to vanity, ordinary actions to habit, and mean actions to fear.'
- Friedrich Nietzsche
'Do not argue with Judas, nube, that would be foolish!'
- D3PART3D
- Friedrich Nietzsche
'Do not argue with Judas, nube, that would be foolish!'
- D3PART3D
You've corrected the syntax for him, but there's still a logical error somewhere. It doesn't evaluate to the hint.
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
I know. I didn't want to do all the work for him.Hex_Rated wrote:You've corrected the syntax for him, but there's still a logical error somewhere. It doesn't evaluate to the hint.
'One will rarely err if extreme actions be ascribed to vanity, ordinary actions to habit, and mean actions to fear.'
- Friedrich Nietzsche
'Do not argue with Judas, nube, that would be foolish!'
- D3PART3D
- Friedrich Nietzsche
'Do not argue with Judas, nube, that would be foolish!'
- D3PART3D
OK guy's time to come clean. This was a test and you all have passed!!!!
Just kidding. It is actualy a friend of mine here at work that is struggeling with her c++ and I suggested to her to come to you ever so helpfull guy's here at the forums. I let her log on with my profile just to get her online as she had a deadline for her assignment. Now that she saw how helpfull you bunch are she will create her own profile. I can't code to save my live (not enough brains), just an administrator.
Thanks again!!!!!!!!
You can pm her (Milkybar)she's hot
Just kidding. It is actualy a friend of mine here at work that is struggeling with her c++ and I suggested to her to come to you ever so helpfull guy's here at the forums. I let her log on with my profile just to get her online as she had a deadline for her assignment. Now that she saw how helpfull you bunch are she will create her own profile. I can't code to save my live (not enough brains), just an administrator.
Thanks again!!!!!!!!
You can pm her (Milkybar)she's hot
You know it is not nice to create a second profile just so you can get your homework assignments done?
That can NOT be at a business level with programming - How does someone get hired with such a lack of skillz?
Sneaky buggger arent you?
That can NOT be at a business level with programming - How does someone get hired with such a lack of skillz?
Sneaky buggger arent you?
My BF2142 Stats:
Slasher : Former member of www.PCFormat.co.za
I have reached the end of my near 5 year forum life. Farewell good days...
slasher (at) webmail (dot) co (dot) za
Slasher : Former member of www.PCFormat.co.za
I have reached the end of my near 5 year forum life. Farewell good days...
slasher (at) webmail (dot) co (dot) za
Well I don't think she can be that hot cause you need hair on your teeth to do what she is trying. She is in admin and now she is trying to learn programming for part of her course in business management or something. I told her it is not easy, but chicks don't listen.
So here is the proof, women don't know everything..lol
I suppose I sould stop nagging or I will start getting some serious chick mail.....
So here is the proof, women don't know everything..lol
I suppose I sould stop nagging or I will start getting some serious chick mail.....
Congrats! :bigups:Milkybar wrote:Just letting you guys know, I passed the assignment...
Feel free to ask if there's anything else that we can help with.
'One will rarely err if extreme actions be ascribed to vanity, ordinary actions to habit, and mean actions to fear.'
- Friedrich Nietzsche
'Do not argue with Judas, nube, that would be foolish!'
- D3PART3D
- Friedrich Nietzsche
'Do not argue with Judas, nube, that would be foolish!'
- D3PART3D