Two Plus Two Poker Forums Programming homework and newbie help thread
 Register FAQ Search Today's Posts Mark Forums Read Video Directory TwoPlusTwo.com

 Notices

 10-12-2014, 05:21 AM #26 daveT S.A.G.E. Master     Join Date: Jun 2005 Location: Why didn't I use Clojure instead? Posts: 21,483 Re: Programming homework and newbie help thread I do know why. I changed your raw_input() to input(). If you convert it back, you won't get the error.
 10-12-2014, 05:29 AM #27 pewpewpew journeyman   Join Date: Dec 2013 Posts: 293 Re: Programming homework and newbie help thread my hero Thanks for all the help
 10-12-2014, 05:45 AM #28 daveT S.A.G.E. Master     Join Date: Jun 2005 Location: Why didn't I use Clojure instead? Posts: 21,483 Re: Programming homework and newbie help thread coolio. Just note that the newest has a slight change in it. I sort of messed up the ordering.
 10-14-2014, 11:38 PM #29 Anais Carpal \'Tunnel     Join Date: Mar 2006 Posts: 6,666 Re: Programming homework and newbie help thread They just tossed a sample selection sort algorithm into this chapter about arrays. Think I'm having a panic attack trying to understand wtf is going on in this program.
 10-21-2014, 03:15 PM #30 tm33 newbie   Join Date: Aug 2012 Posts: 34 Re: Programming homework and newbie help thread Hi, after 3 days of trying really hard, I decided that i need help. Let's have a cube and two points A[x1,y1,z1], B[x2,y2,z2]. I need to calculate the shorthest path between these two points. The path has to be on surface of the cube. If the two points are on the same side, then it is easy. I managed to write a code for situation when they are on the opposite sides. It is somehow working altough it has probably some flaws. But I just can't figure out, what to do when they are on adjacent sides. Obviously I tried using Pythagorean equation in a lot of different ways, but there was always some hole in my code. If you could please just give me some advice. Thank you
 10-21-2014, 04:39 PM #31 e i pi veteran     Join Date: Feb 2010 Location: ☃ Posts: 2,230 Re: Programming homework and newbie help thread Can you solve it with pen & pencil? I guess the key insight for adjacent sides is that if you flatten out the sides it is just a normal shortest path problem. So if you have points (0,a,b) and (c,1,d) for a 1x1x1 cube you will have to travel over the (0,1,z) edge. So you get the distance from both points to the edge and add them and that is one side of the triangle. Then for the lines you drew to the edge, the distance between these two lines along the edge is another side of the triangle. Then you have enough info to use trig to get the angle from one point to another relative to the shared edge. Coding this sounds like a pain in the ass. Sorry edit: Just noticed you only wanted to calculate the distance not produce some equation to describe the path. In this case its just pythagorean with the two found sides. Last edited by e i pi; 10-21-2014 at 04:51 PM. Reason: bla
 10-21-2014, 07:48 PM #32 RoundTower ɹǝʍoʇpunoɹ     Join Date: Feb 2005 Location: soah made my profile Posts: 14,560 Re: Programming homework and newbie help thread I think there are cases where the points are on adjacent sides but the shortest path takes you over a third side. Actually I thought there were some weird paths when you are on opposite sides too.
 10-21-2014, 08:18 PM #33 e i pi veteran     Join Date: Feb 2010 Location: ☃ Posts: 2,230 Re: Programming homework and newbie help thread Ah didn't think too hard about this one. Looked into it and apparently it's a well known problem, http://mathworld.wolfram.com/SpiderandFlyProblem.html
 10-21-2014, 08:23 PM #34 jjshabado Carpal Tunnel     Join Date: Jul 2006 Posts: 21,628 Re: Programming homework and newbie help thread RT: Yeah, you're right. The shortest path here will actually involve going over the top face.
 10-21-2014, 08:23 PM #35 jjshabado Carpal Tunnel     Join Date: Jul 2006 Posts: 21,628 Re: Programming homework and newbie help thread Hah, turns out it takes me at least 5 minutes to draw a ****ty cube.
 10-21-2014, 08:25 PM #36 e i pi veteran     Join Date: Feb 2010 Location: ☃ Posts: 2,230 Re: Programming homework and newbie help thread So I guess you have to iterate through these http://en.wikipedia.org/wiki/Hexomino this looks like a major headache. glad I didn't go to school for compsci
 10-21-2014, 09:07 PM #38 jjshabado Carpal Tunnel     Join Date: Jul 2006 Posts: 21,628 Re: Programming homework and newbie help thread Nice. You can use [ code ] tags to keep formatting of your code. I think the easiest way to fix your program is to move the money logic completely out of your loop. You're keeping track of the number of people in each category anyway - so just use those numbers (checking for your ticket limit) after the loop to do one money calculation. Edit: My bad, I see you have to display the running total. If you've already covered helper methods I'd just create a method that takes in your current counts of users and spits out a ticket amount.
 10-21-2014, 09:29 PM #39 Anais Carpal \'Tunnel     Join Date: Mar 2006 Posts: 6,666 Re: Programming homework and newbie help thread rather, for anything even kinda long, you probably should: Spoiler: Code: ```import java.util.Scanner; public class FestivalAdmission{ public static void main(String[] args){ Scanner input = new Scanner(System.in); final int CHILD_ADMITTED_LIMIT = 50; final int ADULT_ADMITTED_LIMIT = 200; final int SENIOR_ADMITTED_LIMIT = 100; final int CATEGORY_TICKET_LIMIT = 210; final int TOTAL_PEOPLE_ADMITTED_LIMIT = 300; final double GRAND_AMT = 2500.00; final double TICKET = 10.00; int totalPeople = 0; int totalAmount = 0; int children = 0; int adults = 0; int seniors = 0; while (totalPeople < TOTAL_PEOPLE_ADMITTED_LIMIT && children < CHILD_ADMITTED_LIMIT && adults < ADULT_ADMITTED_LIMIT && seniors < SENIOR_ADMITTED_LIMIT && totalAmount < GRAND_AMT){ System.out.print("Welcome to the Festival!Please enter the following information about your party number of children, number of adults, and number of seniors: "); int child = input.nextInt(); int adult = input.nextInt(); int senior = input.nextInt(); children = children + child; adults = adults + adult; seniors = seniors + senior; int remainingChildren = CHILD_ADMITTED_LIMIT - children; int remainingAdults = ADULT_ADMITTED_LIMIT - adults; int remainingSeniors = SENIOR_ADMITTED_LIMIT - seniors; int people = children + adults + seniors; totalPeople = totalPeople + people; int amount = ((children * 5) + (adults * 10) + (seniors * 9)); totalAmount = totalAmount + amount; System.out.println("Running Kids: " + children + " Children ticket left: " + remainingChildren); System.out.println("Running Adults: " + adults + " Adult ticket left :" + remainingAdults); System.out.println("Running Seniors: " + seniors + " Senior ticket left:" + remainingSeniors); System.out.println("Running Total people: " + people); System.out.println("Current GrandAmt: \$" + totalAmount); } if (totalPeople > TOTAL_PEOPLE_ADMITTED_LIMIT) System.out.println("People up to the admitted limit"); if (children > CHILD_ADMITTED_LIMIT) System.out.println("Children up to the admitted limit"); if (adults > ADULT_ADMITTED_LIMIT) System.out.println("Adults up to the admitted limit"); if (seniors > SENIOR_ADMITTED_LIMIT) System.out.println("Seniors up to the admitted limit"); if (totalAmount < GRAND_AMT) System.out.println("Grand Amount surpassed limit"); System.out.println("Admission Closed - Total Money Collected is \$" + totalAmount); System.out.println("Total children admitted was " + children); System.out.println("Total Seniors admitted was " + seniors); System.out.println("Total visitors admitted was " + totalPeople); }```
 10-21-2014, 10:31 PM #40 Anais Carpal \'Tunnel     Join Date: Mar 2006 Posts: 6,666 Re: Programming homework and newbie help thread anyone know offhand why a c++ int function would return 99 or 100 when you have not written any condition that returns either value?
10-21-2014, 10:49 PM   #41
Carpal Tunnel

Join Date: Jul 2006
Posts: 21,628
Re: Programming homework and newbie help thread

Quote:
 Originally Posted by Anais anyone know offhand why a c++ int function would return 99 or 100 when you have not written any condition that returns either value?

It's been a long time since I've written C++ but I'd guess it's a memory/pointer/reference issue. Can you post the code?

10-21-2014, 10:54 PM   #42
Carpal \'Tunnel

Join Date: Sep 2002
Location: Russian Troll
Posts: 20,752
Re: Programming homework and newbie help thread

Quote:
 Originally Posted by Anais anyone know offhand why a c++ int function would return 99 or 100 when you have not written any condition that returns either value?
Uninitialized return value would be my guess or you are clobbering some data due to a bug are my guesses. Post the code.

 10-21-2014, 11:11 PM #43 adios Carpal \'Tunnel   Join Date: Sep 2002 Location: Russian Troll Posts: 20,752 Re: Programming homework and newbie help thread In C, how would you dynamically allocate 1K bytes and have them all be zero with one standard C library call?
10-21-2014, 11:31 PM   #44
Anais
Carpal \'Tunnel

Join Date: Mar 2006
Posts: 6,666
Re: Programming homework and newbie help thread

It's a good night. New function is outputting a string a ╠╠╠╠╠╠╠╠

what even is that?

Quote:
 Originally Posted by adios Uninitialized return value would be my guess or you are clobbering some data due to a bug are my guesses. Post the code.
The weird part is that MY code is returning the proper values. The part that's supposed to be returning a 0 is what the teacher wrote. And it returns 99 or 100.

THIS IS ALL SOMEONE ELSE'S FAULT!

function code below:

Spoiler:

we're supposed to compare two character arrays and see if they are the same, or if they are or are not entered in alphabetical order, and give a return indicating which.

 10-21-2014, 11:37 PM #45 KatoKrazy veteran     Join Date: Jan 2009 Location: Roch, MN Posts: 3,079 Re: Programming homework and newbie help thread Index will never be \0 you meant to check if the values in the arrays at index are \0
 10-21-2014, 11:45 PM #46 Anais Carpal \'Tunnel     Join Date: Mar 2006 Posts: 6,666 Re: Programming homework and newbie help thread My man!
10-22-2014, 03:41 PM   #47
Carpal \'Tunnel

Join Date: Sep 2002
Location: Russian Troll
Posts: 20,752
Re: Programming homework and newbie help thread

Quote:
 Originally Posted by KatoKrazy Index will never be \0 you meant to check if the values in the arrays at index are \0
Actually due to his bug(s) it could.

@anais - notice that your code can return an uninitialized value and probably does. If none of the if conditions hold. The pro tip is to initialize a return value in a variable at the beginning of the function then modify it in the code.

Last edited by adios; 10-22-2014 at 03:48 PM.

 10-22-2014, 06:24 PM #48 Anais Carpal \'Tunnel     Join Date: Mar 2006 Posts: 6,666 Re: Programming homework and newbie help thread Oh, so like put an int final = 0;, then modify that with the if statements, then return final? That makes sense. Also, I figured out why I was getting those weird ascii 204 characters in another program. Forgot to assign a null character to the end of a char array and it was spitting out weird garbage. Ugh, c++ is such a pita.
 10-23-2014, 11:16 AM #49 jmakin debauchery and general idiocy     Join Date: Jan 2008 Location: Streaming Posts: 24,745 Re: Programming homework and newbie help thread If you don't put a null character at the end of a c string, it doesn't know when to stop reading data and is likely just pulling whatever random crap is in memory. I always add an arbitrary return value at the end of my function, if i have a bunch of if statements like you do, even if you're confident there's no way it'll be reached. Most IDEs will warn you if you don't do this. Pretty sure java won't even compile if you don't do that.
 10-23-2014, 12:05 PM #50 KatoKrazy veteran     Join Date: Jan 2009 Location: Roch, MN Posts: 3,079 Re: Programming homework and newbie help thread Ugh, two tests today. Thankfully Theory of Algorithms test is supposed to be much easier than the first one.

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Two Plus Two     Two Plus Two Magazine Forum     The Best of Two Plus Two     The Two Plus Two Bonus Program     Two Plus Two Pokercast     Two Plus Two Videos     Marketplace         General Marketplace         Staking - Offering Stakes         Staking - Seeking Stakes         Staking - Selling Shares - Online         Staking - Selling Shares - Live         Staking Rails         Transaction Feedback & Disputes     Commercial Marketplace     Staking - Offering Stakes     About the Forums Fantasy Sports     Fantasy Sports         Sporting Events General Poker Discussion     Beginners Questions     Live Casino Poker         Poker Venues         Regional Communities     Poker Goals & Challenges     Books and Publications     Poker Theory     Poker Tells/Behavior, hosted by: Zachary Elwood     News, Views, and Gossip     Twitch - Watch and Discuss Live Online Poker     Televised Poker     Home Poker     Poker Legislation & PPA Discussion hosted by Rich Muny     That's What She Said!     Poker Beats, Brags, and Variance Coaching/Training     Coaching Advice     Cash Game Poker Coach Listings     Tournament/SNG Poker Coach Listings International Forums     Deutsch         BBV [German]     Français     Two Plus Two en Espańol No Limit Hold'em     Medium-High Stakes PL/NL     Micro-Small Stakes PL/NL     Medium-High Stakes Full Ring     Micro-Small Stakes Full Ring     Heads Up NL     Live Low-stakes NL Limit Texas Hold'em     Mid-High Stakes Limit     Micro-Small Stakes Limit Tournament Poker     STT Strategy     Heads Up SNG and Spin and Gos     Mid-High Stakes MTT     Small Stakes MTT     MTT Community     MTTc - Live         WPT.com Other Poker     High Stakes PL Omaha     Small Stakes PL Omaha     Omaha/8     Stud     Draw and Other Poker General Gambling     Backgammon Forum hosted by Bill Robertie.     Probability     Psychology     Sports Betting     Other Gambling Games Internet Poker     Internet Poker         Winning Poker Network         nj.partypoker.com         Global Poker     Commercial Software     Software         Commercial Software         Free Software     nj.partypoker.com         WPT.com 2+2 Communities     Other Other Topics         OOTV         Game of Thrones     The Lounge: Discussion+Review     EDF     Las Vegas Lifestyle     BBV4Life         omg omg omg     House of Blogs Sports and Games     Sporting Events         Single-Team Season Threads         Fantasy Sports     Wrestling     Golf     Pool, Snooker, and Billiards     Chess and Other Board Games     Video Games         League of Legends         Hearthstone     Puzzles and Other Games Other Topics     Politics         Economics     Business, Finance, and Investing     Travel     Science, Math, and Philosophy     History     Religion, God, and Theology     Health and Fitness     Student Life     The Studio     Laughs or Links!     Computer Technical Help     Programming

All times are GMT -4. The time now is 09:31 PM.

 Contact Us - Two Plus Two Publishing LLC - Privacy Statement - Top