Open Side Menu Go to the Top
Register
Programming homework and newbie help thread Programming homework and newbie help thread

10-12-2014 , 05:21 AM
I do know why. I changed your raw_input() to input(). If you convert it back, you won't get the error.
Programming homework and newbie help thread Quote
10-12-2014 , 05:29 AM
my hero Thanks for all the help
Programming homework and newbie help thread Quote
10-12-2014 , 05:45 AM
coolio. Just note that the newest has a slight change in it. I sort of messed up the ordering.
Programming homework and newbie help thread Quote
10-14-2014 , 11:38 PM
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.
Programming homework and newbie help thread Quote
10-21-2014 , 03:15 PM
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
Programming homework and newbie help thread Quote
10-21-2014 , 04:39 PM
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
Programming homework and newbie help thread Quote
10-21-2014 , 07:48 PM
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.
Programming homework and newbie help thread Quote
10-21-2014 , 08:18 PM
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
Programming homework and newbie help thread Quote
10-21-2014 , 08:23 PM
RT: Yeah, you're right.



The shortest path here will actually involve going over the top face.
Programming homework and newbie help thread Quote
10-21-2014 , 08:23 PM
Hah, turns out it takes me at least 5 minutes to draw a ****ty cube.
Programming homework and newbie help thread Quote
10-21-2014 , 08:25 PM
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
Programming homework and newbie help thread Quote
10-21-2014 , 08:35 PM
ok so! I already made this program and submitted it about a week ago. I got a 13/15 I didnt know about how to include the category ticket limit into my program. the first spoiler is my assignment and then the second spoiler is the program i make all by myself How do i fixn it?


Spoiler:


Due : see calendar

Write a Java program to control and report the admissions to a Festival. Groups of

people arrive in “Parties” to the Festival. Each Party has children, adults and seniors.

Adults are charged 10.00, children are charged 50% of an adult ticket, and seniors

are charged 90% of an adult ticket. Parties of people are admitted until 1 or more of

6 different limits are reached. See part B for the limit values.

NOTE: The closing of the Festival will only take place after a complete
party has been admitted. For that last group, all tickets purchases
above the catagory ticket limit will be free. For example if the current
number of seniors admitted is 28 and there are 190 seniors in the party that
just arrived, 182 seniors will be charged the senior ticket price and 8 senoirs will
be admitted free.




************************************************** *********************

A. Use a flag controlled loop to solve the problem.





************************************************** *********************

B.

Use the following constants in your program:

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;





************************************************** ********************

C.

Use Scanner class standard input to bring in data for number of children, number of adults,

and number of seniors in the party.

Calculate the bill for the party. Update the 5 Running Totals . Display the

Running Totals on System.out after each party has be admitted to the

Festival.



************************************************** ********************

D.

The Festival will be closed when any of the limits have been reached.

On System.out display all reasons that the Festival was closed.

Print the Conclusion for all 5 Accumulators before exit.





************************************************** ********************

Sample output console(System.out) is as following :



*******Festival Report********

"User inputs 20 10 28" // NOTE: This line in NOT part of the report, the line only shows what the user entered for input

Running Kids: 20 Children ticket left : 190

Running Adults: 10 Adult ticket left : 200

Running Seniors: 28 Senior ticket left : 182

Running Total people:58

Current GrandAmt: $452.0



"User inputs 40 10 190" // NOTE: This line in NOT part of the report, the line only shows what the user entered for input

Running Kids: 60 Children ticket left : 150

Running Adults: 20 Adult ticket left : 190

Running Seniors: 218 Senior ticket left : -8



Running Total people:298

Current GrandAmt: $2390.0

-------------------------------------------------------------------------------------------

Children up to the admitted limit.

Senior up to the admitted limit.

Senior up to the category ticket limit



Admission Closed - Total Money Collected is $2390.0

Total children admitted was 60

Total adults admitted was 20

Total seniors admitted was 218

Total visitors admitted was 298



************************************************** *******************




Spoiler:
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);



}

Programming homework and newbie help thread Quote
10-21-2014 , 09:07 PM
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.
Programming homework and newbie help thread Quote
10-21-2014 , 09:29 PM
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);



}
Programming homework and newbie help thread Quote
10-21-2014 , 10:31 PM
anyone know offhand why a c++ int function would return 99 or 100 when you have not written any condition that returns either value?
Programming homework and newbie help thread Quote
10-21-2014 , 10:49 PM
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?
Programming homework and newbie help thread Quote
10-21-2014 , 10:54 PM
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.
Programming homework and newbie help thread Quote
10-21-2014 , 11:11 PM
In C, how would you dynamically allocate 1K bytes and have them all be zero with one standard C library call?
Programming homework and newbie help thread Quote
10-21-2014 , 11:31 PM
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:
bolded was provided by professor
Code:
int stringCompare1(char s1[], char s2[])
{
	int index = 0;

	while (s1[index] == s2[index] && index != '\0')
	{
		index++;
	}


	if (s1[index] == '\0' && s2[index] == '\0')
		return 0;

	if (s1[index] > s2[index])
		return 1;

	if (s1[index] < s2[index])
		return -1;

}


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.
Programming homework and newbie help thread Quote
10-21-2014 , 11:37 PM
Index will never be \0 you meant to check if the values in the arrays at index are \0
Programming homework and newbie help thread Quote
10-21-2014 , 11:45 PM
My man!
Programming homework and newbie help thread Quote
10-22-2014 , 03:41 PM
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.
Programming homework and newbie help thread Quote
10-22-2014 , 06:24 PM
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.
Programming homework and newbie help thread Quote
10-23-2014 , 11:16 AM
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.
Programming homework and newbie help thread Quote
10-23-2014 , 12:05 PM
Ugh, two tests today. Thankfully Theory of Algorithms test is supposed to be much easier than the first one.
Programming homework and newbie help thread Quote

      
m