Current Events > I hate programming.

Topic List
Page List: 1
LookANinja
01/29/18 11:19:04 PM
#1:


Don't know why i want to do this for a living.

Gotta get the length and width of a rectangle from user.
Call a function to double the entered length and width (return type void, must be passed by address/pointer)
Call another function to calculate area of new enlarged rectangle(must be passed by value)
Display new height, length, area.

I got this so far, and im stuck. I know my variable names suck.

#include <iostream>
using namespace std;
void doublelw(int *pl,int *pw,int *pl2,int* pw2);
int calcarea(int na);

int main()
{
int l,w,na,pl2,pw2;
cout<<"Enter Length and Width";
cin>>l>>w;
doublelw(&l,&w,&pl2,&pw2);
calcarea (na);
cout<<"Length:"<<pl2<<"Width:"<<pw2<<"Area:"<<na;
}
void doublelw(int *pl,int *pw,int* pl2, int* pw2)
{
*pl2= *pl * 2;
*pw2= *pw * 2;
}
int calcarea(int na)
{
pl2*pw2 = na;
return na;
}
---
... Copied to Clipboard!
armandro
01/29/18 11:21:37 PM
#2:


should have done pro gaming instead
---
... Copied to Clipboard!
LookANinja
01/29/18 11:55:28 PM
#3:


#include <iostream>
using namespace std;
void doublelh(int *plen,int *phei,int *plen2,int* phei2);
int calcarea( int len, int hei);

int main()
{
int len,hei,na,plen2,phei2;
int *pllen = &len;
int *phei = &hei;
cout<<"Enter Length and height"<<"\n";
cin>>len>>hei;
doublelh(&len,&hei,&plen2,&phei2);
na=calcarea (len,hei);
cout<<"Length:"<<plen2<<"\t"<<"Width:"<<phei2<<"\t"<<"Area:"<<na;
}
void doublelh(int *plen,int *phei,int* plen2, int* phei2)
{
*plen2= *plen * 2;
*phei2= *phei * 2;
}
int calcarea( int len, int hei)
{

return (len*hei);
}

Almost got it, but the Area it's calculating is the width and length of the original values.
---
... Copied to Clipboard!
voldothegr8
01/29/18 11:56:52 PM
#4:


I'm in IT and hated it too in college.
---
Oda break tracker 2018- 0 (1) | THE Ohio State: 11-2 | Oakland Raiders: 6-10
Super Mario Maker Profile: 1237-0000-0073-02FE
... Copied to Clipboard!
Sad_Face
01/30/18 12:06:49 AM
#5:


LookANinja posted...
int calcarea( int len, int hei)
{

return (len*hei);
}


Almost got it, but the Area it's calculating is the width and length of the original values.


That's because you're using the variables for the width and length of the original values. What did variables did you save the doubled versions in?
---
imgtc.com/i/4HgTl0ebzq.jpg imgtc.com/i/60CWP2Gtlg.gif
... Copied to Clipboard!
LookANinja
01/30/18 12:10:20 AM
#6:


For some reason i thought using pointers in the first function would change the value of the variable at that address. So len and hei will become the double of whatever was originally input.

#include <iostream>
using namespace std;
void doublelh(int *plen,int *phei,int *plen2,int* phei2);
int calcarea( int len, int hei);

int main()
{
int len,hei,na,plen2,phei2;
cout<<"Enter Length and height"<<"\n";
cin>>len>>hei;
doublelh(&len,&hei,&plen2,&phei2);
int *plen = &len;
int *phei = &hei;
na=calcarea (plen2,phei2);
cout<<"Length:"<<plen2<<"\t"<<"Width:"<<phei2<<"\t"<<"Area:"<<na;
}
void doublelh(int *plen,int *phei,int* plen2, int* phei2)
{
*plen2= *plen * 2;
*phei2= *phei * 2;
}
int calcarea( int plen2, int phei2)
{

return (plen2*phei2);
}

I got it working like this, but does it still fulfill the requirements of the assignment?
1st function pass by pointer
2nd function pass by value
---
... Copied to Clipboard!
Sad_Face
01/30/18 12:21:36 AM
#7:


It looks fine to me.
---
imgtc.com/i/4HgTl0ebzq.jpg imgtc.com/i/60CWP2Gtlg.gif
... Copied to Clipboard!
TheMarthKoopa
01/30/18 12:23:35 AM
#8:


I love programming because it's so easy
... Copied to Clipboard!
LookANinja
01/30/18 12:24:12 AM
#9:


Alright thanks for your help! My next assignment will be similar, but with volume and using pass by reference. Hopefully it's not too complicated. D:
---
... Copied to Clipboard!
FFVII_REMAKE
01/30/18 12:27:54 AM
#10:


Programming jobs pay you 6 figures for easy shit.
... Copied to Clipboard!
Ben111
01/30/18 12:29:01 AM
#11:


What programming tool are you using?
---
My 3ds friend code is 2852-7795-4118
I like video games
... Copied to Clipboard!
Omegle
01/30/18 12:30:19 AM
#12:


lol if you can't do this you should really reconsider what you're doing with your life
---
Ask anything you like, but try to keep questions open-ended and thought-provoking.
... Copied to Clipboard!
LookANinja
01/30/18 12:34:10 AM
#13:


Ben111 posted...
What programming tool are you using?

Codeblocks.

I feel too old to be reconsidering my life choices >_<
---
... Copied to Clipboard!
TheMarthKoopa
01/30/18 12:35:47 AM
#14:


LookANinja posted...
Codeblocks.

Use Visual Studio
... Copied to Clipboard!
Vita_Aeterna
01/30/18 12:36:09 AM
#15:


Wow, looking at the work programmers do...god damn, I'm surprised y'all don't want to kill yourselves.
---
"Bear Island knows no king but the King in the North, whose name is STARK."
... Copied to Clipboard!
Ben111
01/30/18 12:40:19 AM
#16:


Vita_Aeterna posted...
Wow, looking at the work programmers do...god damn, I'm surprised y'all don't want to kill yourselves.

Idk I am just starting out and it is not that hard. But I literally just started this quarter this month so I am still very inexperienced. So far I think it is fun
---
My 3ds friend code is 2852-7795-4118
I like video games
... Copied to Clipboard!
#17
Post #17 was unavailable or deleted.
LookANinja
01/30/18 3:08:55 PM
#18:


... Copied to Clipboard!
Sativa_Rose
01/30/18 3:24:58 PM
#19:


Coding is cool dude, though this is coming from someone who still debugs using print statements rather than an actual debugging tool.

But yeah, just throw some print statements in there to figure out what the F is going wrong, and then fix it, and then move on to the next problem. That's what I do. Persistence is key.
---
I may not go down in history, but I will go down on your sister.
... Copied to Clipboard!
Giant_Aspirin
01/30/18 3:26:48 PM
#20:


Sativa_Rose posted...
Coding is cool dude, though this is coming from someone who still debugs using print statements rather than an actual debugging tool.

But yeah, just throw some print statements in there to figure out what the F is going wrong, and then fix it, and then move on to the next problem. That's what I do. Persistence is key.


or learn to use a debugger. it's an invaluable tool. once i learned to use one i never, ever, ever went back to printing out stuff as a means of debugging
---
Playing: Dark Souls III (PC)
(~);} - Get out the pans, don't just stand there dreamin' - {;(~)
... Copied to Clipboard!
Sativa_Rose
01/30/18 3:27:36 PM
#21:


Giant_Aspirin posted...
Sativa_Rose posted...
Coding is cool dude, though this is coming from someone who still debugs using print statements rather than an actual debugging tool.

But yeah, just throw some print statements in there to figure out what the F is going wrong, and then fix it, and then move on to the next problem. That's what I do. Persistence is key.


or learn to use a debugger. it's an invaluable tool. once i learned to use one i never, ever, ever went back to printing out stuff as a means of debugging


This is something I should do, but right now I have other priorities. I'm basically the only actual programmer at my company, the other guys are like math/science people who put everything in one gigantic function and repeat a lot of code.
---
I may not go down in history, but I will go down on your sister.
... Copied to Clipboard!
Questionmarktarius
01/30/18 3:28:57 PM
#22:


LookANinja posted...
(return type void, must be passed by address/pointer)

That's just asking for null pointers and memory leaks.
... Copied to Clipboard!
flussence
01/30/18 3:30:08 PM
#23:


should've used Rust
---
u
... Copied to Clipboard!
mario2000
01/30/18 3:31:04 PM
#24:


please name your variables better tc because yikes
---
Arrrr the SS Goku, Mighty fine boat... -fatmatt
Hope Frieza doesn't chuck an Iceberg at the Goku, otherwise it's all over. -Nekoslash
... Copied to Clipboard!
COVxy
01/30/18 3:32:30 PM
#26:


Sativa_Rose posted...
Coding is cool dude, though this is coming from someone who still debugs using print statements rather than an actual debugging tool.

But yeah, just throw some print statements in there to figure out what the F is going wrong, and then fix it, and then move on to the next problem. That's what I do. Persistence is key.


I do this, but mainly because I'm not a programmer and only use Matlab and python.
---
=E[(x-E[x])(y-E[y])]
... Copied to Clipboard!
Questionmarktarius
01/30/18 3:38:02 PM
#27:


Sativa_Rose posted...
But yeah, just throw some print statements in there to figure out what the F is going wrong, and then fix it, and then move on to the next problem. That's what I do. Persistence is key.

There's where understanding algorithms helps.
Knowing what's going in, what's supposed to come out, and all the steps needed in between, is far more important than the actual "coding" bits.
... Copied to Clipboard!
treewojima
01/30/18 3:43:10 PM
#28:


Giant_Aspirin posted...
Sativa_Rose posted...
Coding is cool dude, though this is coming from someone who still debugs using print statements rather than an actual debugging tool.

But yeah, just throw some print statements in there to figure out what the F is going wrong, and then fix it, and then move on to the next problem. That's what I do. Persistence is key.


or learn to use a debugger. it's an invaluable tool. once i learned to use one i never, ever, ever went back to printing out stuff as a means of debugging


use both. I have logging facilities in place to give me an idea of what's going on and to narrow down the problem, then when things go askew I fire up the debugger
... Copied to Clipboard!
bobtuse
01/30/18 3:44:47 PM
#29:


Have you considered passing your doubled width/height variables by reference, or is that not allowed?
---
.
... Copied to Clipboard!
Sativa_Rose
01/30/18 3:45:28 PM
#30:


treewojima posted...
Giant_Aspirin posted...
Sativa_Rose posted...
Coding is cool dude, though this is coming from someone who still debugs using print statements rather than an actual debugging tool.

But yeah, just throw some print statements in there to figure out what the F is going wrong, and then fix it, and then move on to the next problem. That's what I do. Persistence is key.


or learn to use a debugger. it's an invaluable tool. once i learned to use one i never, ever, ever went back to printing out stuff as a means of debugging


use both. I have logging facilities in place to give me an idea of what's going on and to narrow down the problem, then when things go askew I fire up the debugger


With the current system I am working on, I usually have to have it running for like 6 hours before any bugs start to show up. So I've been exclusively using logging since I don't even know how you would use a debugger in a situation like that.

It's a system where I have a client constantly sending data over TCP to a server that then does some shit with it and sends some results back.
---
I may not go down in history, but I will go down on your sister.
... Copied to Clipboard!
Giant_Aspirin
01/30/18 3:48:26 PM
#31:


treewojima posted...
Giant_Aspirin posted...
Sativa_Rose posted...
Coding is cool dude, though this is coming from someone who still debugs using print statements rather than an actual debugging tool.

But yeah, just throw some print statements in there to figure out what the F is going wrong, and then fix it, and then move on to the next problem. That's what I do. Persistence is key.


or learn to use a debugger. it's an invaluable tool. once i learned to use one i never, ever, ever went back to printing out stuff as a means of debugging


use both. I have logging facilities in place to give me an idea of what's going on and to narrow down the problem, then when things go askew I fire up the debugger


i didnt mean to imply that printing things is never a good idea because you're exactly right -- logging is also invaluable.

Sativa_Rose posted...
I don't even know how you would use a debugger in a situation like that.


remote debuggers are a thing and are really neat.
---
Playing: Dark Souls III (PC)
(~);} - Get out the pans, don't just stand there dreamin' - {;(~)
... Copied to Clipboard!
treewojima
01/30/18 3:48:34 PM
#32:


Sativa_Rose posted...
treewojima posted...
Giant_Aspirin posted...
Sativa_Rose posted...
Coding is cool dude, though this is coming from someone who still debugs using print statements rather than an actual debugging tool.

But yeah, just throw some print statements in there to figure out what the F is going wrong, and then fix it, and then move on to the next problem. That's what I do. Persistence is key.


or learn to use a debugger. it's an invaluable tool. once i learned to use one i never, ever, ever went back to printing out stuff as a means of debugging


use both. I have logging facilities in place to give me an idea of what's going on and to narrow down the problem, then when things go askew I fire up the debugger


With the current system I am working on, I usually have to have it running for like 6 hours before any bugs start to show up. So I've been exclusively using logging since I don't even know how you would use a debugger in a situation like that.

It's a system where I have a client constantly sending data over TCP to a server that then does some shit with it and sends some results back.


Use those logs to cook up erroneous data or activity, then create some unit tests or debugging backdoors to "force" the application to behave that way on demand?
... Copied to Clipboard!
LookANinja
01/30/18 3:50:09 PM
#33:


bobtuse posted...
Have you considered passing your doubled width/height variables by reference, or is that not allowed?

that's what i'm doing for the next assignment (Cube, and the entered w/l/h is halved instead of doubled) I think that's what i was thinking when i said i thought pass by pointer would change the value at the address, but it's pass by reference that does that right?
---
... Copied to Clipboard!
Sativa_Rose
01/30/18 3:50:17 PM
#34:


treewojima posted...
Sativa_Rose posted...
treewojima posted...
Giant_Aspirin posted...
Sativa_Rose posted...
Coding is cool dude, though this is coming from someone who still debugs using print statements rather than an actual debugging tool.

But yeah, just throw some print statements in there to figure out what the F is going wrong, and then fix it, and then move on to the next problem. That's what I do. Persistence is key.


or learn to use a debugger. it's an invaluable tool. once i learned to use one i never, ever, ever went back to printing out stuff as a means of debugging


use both. I have logging facilities in place to give me an idea of what's going on and to narrow down the problem, then when things go askew I fire up the debugger


With the current system I am working on, I usually have to have it running for like 6 hours before any bugs start to show up. So I've been exclusively using logging since I don't even know how you would use a debugger in a situation like that.

It's a system where I have a client constantly sending data over TCP to a server that then does some shit with it and sends some results back.


Use those logs to cook up erroneous data or activity, then create some unit tests or debugging backdoors to "force" the application to behave that way on demand?


This is the kind of thing I need to start doing. I have to up my game a bit.
---
I may not go down in history, but I will go down on your sister.
... Copied to Clipboard!
Sativa_Rose
01/30/18 3:51:25 PM
#35:


LookANinja posted...
bobtuse posted...
Have you considered passing your doubled width/height variables by reference, or is that not allowed?

that's what i'm doing for the next assignment (Cube, and the entered w/l/h is halved instead of doubled) I think that's what i was thinking when i said i thought pass by pointer would change the value at the address, but it's pass by reference that does that right?


Think about what you are passing to a function. Are you passing just a value, or are you passing an address that contains the value you are wanting to work with?
---
I may not go down in history, but I will go down on your sister.
... Copied to Clipboard!
bobtuse
01/30/18 3:54:44 PM
#36:


LookANinja posted...
bobtuse posted...
Have you considered passing your doubled width/height variables by reference, or is that not allowed?

that's what i'm doing for the next assignment (Cube, and the entered w/l/h is halved instead of doubled) I think that's what i was thinking when i said i thought pass by pointer would change the value at the address, but it's pass by reference that does that right?

You can change the value either way, although you'll have to dereference the pointer. What makes passing by ref simpler in many cases is that you know it will be a valid piece of memory. The advantage of pointers is that they can be set to a null value and updated after initialization.
---
.
... Copied to Clipboard!
CelestialVoices
01/30/18 3:59:13 PM
#37:


... Copied to Clipboard!
LookANinja
01/30/18 6:25:11 PM
#38:


bobtuse posted...
LookANinja posted...
bobtuse posted...
Have you considered passing your doubled width/height variables by reference, or is that not allowed?

that's what i'm doing for the next assignment (Cube, and the entered w/l/h is halved instead of doubled) I think that's what i was thinking when i said i thought pass by pointer would change the value at the address, but it's pass by reference that does that right?

You can change the value either way, although you'll have to dereference the pointer. What makes passing by ref simpler in many cases is that you know it will be a valid piece of memory. The advantage of pointers is that they can be set to a null value and updated after initialization.

Now i'm worried i did the assignment wrong and was supposed to dereference the pointer.
---
... Copied to Clipboard!
Topic List
Page List: 1