Ok thanks that helped, but now I have bigger problems, for some reason the objects won't go in the array they just get error highlights.
[code]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TopTrumps
{
class Program
{
static void Main(string[] args)
{
string gameState = "firstRun";
string playerName;
while (true)
{
if (gameState == "start")
{
Console.Write("Welcome to Top Trumps!\n\nPlease enter a player name: ");
playerName = Console.ReadLine();
Console.Clear();
gameState = "play";
}
if (gameState == "play")
{
Cards.Create();
}
}
}
}
class Card
{
public string name;
public int level;
public int vitality;
public Card(string nm, int lev, int vit)
{
name = nm;
level = lev;
vitality = vit;
}
}
public static class Cards
{
public string[] categories = { "Level", "Vitality", "Strength", "Dexterity", "Faith" };
public object[] allCards;
public object[] playersHand;
public object[] compsHand;
public static void Create()
{
Card card1 = new Card("Black Knight", 75, 75);
Card card2 = new Card("Darkwraith Knight", 60, 60);
Card card3 = new Card("Undead Mage", 45, 50);
Card card4 = new Card("Tree Lizard", 30, 40);
Card card5 = new Card("Serpent Soldier", 55, 55);
Card card6 = new Card("Anor Londo Guard", 65, 70);
Card card7 = new Card("Drake", 85, 95);
Card card8 = new Card("Demonite Demon", 80, 85);
Card card9 = new Card("Hollow Soldier", 10, 25);
Card card10 = new Card("Giant Skeleton", 40, 65);
allCards = { card1, card2, card3, card4, card5, card6, card7, card8, card9, card10 };
}
public static void Shuffle()
{
}
public static void Deal()
{
int i = 0;
foreach (object card in cards)
{
if (playersHand.Length <= 4)
{
playersHand[i] = card;
}
else
{
compsHand[i] = card;
}
i++;
}
}
}
}
[/code]
i think dark souls is copyrighted
don't you try to make a spinoff
oh my god fuck fuck fuck
i got my output working when i was at school but when i loaded it up at home it totally broke
oh god what did i do
[URL="http://pastebin.com/wQdvkHzh"]Search Function[/URL], called by main, calls [URL="http://pastebin.com/qKj1DhsQ"]OutputFunction[/URL], which should theoretically format and output it correctly. (I commented out the substring title statement just in case that was the problem. It was not.)
Unfortunately, the output ends up looking like this:
[img_thumb]http://i.imgur.com/3DnMtR6.png[/img_thumb]
oh my god what happened help me
Is there something wrong with this code? I can't seem to get it to work for some reason, and I'm not entirely sure if the math is wrong, the way I'm using to determine if it's a line segment (min and max), if there's a better way of doing it, or what.
[code]public clsPoint LineIntersectLine(clsPoint p1,clsPoint p2, clsPoint p3, clsPoint p4)
{
double m1; double m2; // slopes
//first convert the numbers to an inverse y axis coordinate
p1.y = -p1.y;
p2.y = -p2.y;
p3.y = -p3.y;
p4.y = -p4.y;
//if the slope is not real
if (p2.x - p1.x != 0)
m1 = (p2.y - p1.y)/(p2.x - p1.x);//find slope of first segment
else m1 = 99999999*Math.signum(p2.y - p1.y); //set it to a really high number just to approximate
//find slope for second line segment
if (p4.x - p3.x != 0)
m2 = (p4.y - p3.y)/(p4.x - p3.x);
else m2 = 99999999*Math.signum(p4.y - p3.y);
// if no slope or line is the same
if (m2 - m1 == 0)
{
p1.y = -p1.y;
p2.y = -p2.y;
p3.y = -p3.y;
p4.y = -p4.y;
return null;//no intersection
}
//find the x value of the intersection
double x = (p1.y*(1+m1) + p3.y*(1+m2)) / (m2 - m1);
//find the y value for plugging in the value we just got into the first line
double y = (p1.y + m1*(x));
//now check to see if the line is inside the segments
double minx = Math.min(p3.x, p4.x);
double miny = Math.min(-p3.y, -p4.y);
double maxx = Math.max(p3.x, p4.x);
double maxy = Math.max(-p3.y, -p4.y);
double minx2 = Math.min(p1.x, p2.x);
double miny2 = Math.min(-p1.y, -p2.y);
double maxx2 = Math.max(p1.x, p2.x);
double maxy2 = Math.max(-p1.y, -p2.y);
//convert them back to the regular axis
p1.y = -p1.y;
p2.y = -p2.y;
p3.y = -p3.y;
p4.y = -p4.y;
// if inside the line segments
if ((x < maxx && x > minx && y > miny && y < maxy) && (x < maxx2 && x > minx2 && y > miny2 && y < maxy2))
{//the line segments intersect
clsPoint intersectionpoint = new clsPoint(x,y,0);
return intersectionpoint;
}
else // they don't intersect
return null;
}[/code]
[QUOTE=Zinayzen;40486455]oh my god fuck fuck fuck
i got my output working when i was at school but when i loaded it up at home it totally broke
oh god what did i do
[URL="http://pastebin.com/wQdvkHzh"]Search Function[/URL], called by main, calls [URL="http://pastebin.com/qKj1DhsQ"]OutputFunction[/URL], which should theoretically format and output it correctly. (I commented out the substring title statement just in case that was the problem. It was not.)
Unfortunately, the output ends up looking like this:
[img_thumb]http://i.imgur.com/3DnMtR6.png[/img_thumb]
oh my god what happened help me[/QUOTE]
Take a look at std::left. I think it would work with something like this:
[code]std::cout << std::left << std::setfill(' ')
<< std::setw(47) << movPtr -> title << std::setw(0) << " "
<< std::setw(4) << movPtr -> year << std::setw(0) << " "
<< std::setw(7) << movPtr -> rating << std::setw(0) << " "[/code]
[editline]1st May 2013[/editline]
[QUOTE=JakeAM;40484881]Ok thanks that helped, but now I have bigger problems, for some reason the objects won't go in the array they just get error highlights.
[code]// snip
public string[] categories = { "Level", "Vitality", "Strength", "Dexterity", "Faith" };
public object[] allCards;
public object[] playersHand;
public object[] compsHand;
public static void Create()
{
Card card1 = new Card("Black Knight", 75, 75);
Card card2 = new Card("Darkwraith Knight", 60, 60);
Card card3 = new Card("Undead Mage", 45, 50);
Card card4 = new Card("Tree Lizard", 30, 40);
Card card5 = new Card("Serpent Soldier", 55, 55);
Card card6 = new Card("Anor Londo Guard", 65, 70);
Card card7 = new Card("Drake", 85, 95);
Card card8 = new Card("Demonite Demon", 80, 85);
Card card9 = new Card("Hollow Soldier", 10, 25);
Card card10 = new Card("Giant Skeleton", 40, 65);
allCards = { card1, card2, card3, card4, card5, card6, card7, card8, card9, card10 };
}
//snip[/code][/QUOTE]
First you want the type for the arrays to be more precise than object.
And then the problem is, that you can only assign an initialize list (I don't know if this is the proper term for that { ... }-style list in C#) to initialize an array, but not to assign to it.
You can initialize it though like you initialized the categories-array:
[code]Card[] allCards = {
new Card("Black Knight", 75, 75),
new Card("Darkwraith Knight", 60, 60),
...
}[/code]
If the creation depends on a function-parameter though, then you can do this:
[code]allCards = new[] {
new Card("Black Knight", 75, 75),
new Card("Darkwraith Knight", 60, 60),
...
}[/code]
[editline]1st May 2013[/editline]
[QUOTE=DesolateGrun;40483690]How do you make a splash screen appear first and then open a different window after a couple of seconds in JAVA?[/QUOTE]
[code]Window splash = new Window(...);
Window different = new Window(...);
splash.setVisible(true);
Thread.sleep(3000);
splash.setVisible(false);
different.setVisible(true);[/code]
I think this works fine, because events are handled in a separate thread.
Am I mistaken?
[editline]1st May 2013[/editline]
[QUOTE=Xystus234;40486632]Is there something wrong with this code? I can't seem to get it to work for some reason, and I'm not entirely sure if the math is wrong, the way I'm using to determine if it's a line segment (min and max), if there's a better way of doing it, or what.
[code]public clsPoint LineIntersectLine(clsPoint p1,clsPoint p2, clsPoint p3, clsPoint p4)
{
double m1; double m2; // slopes
//first convert the numbers to an inverse y axis coordinate
p1.y = -p1.y;
p2.y = -p2.y;
p3.y = -p3.y;
p4.y = -p4.y;
//if the slope is not real
if (p2.x - p1.x != 0)
m1 = (p2.y - p1.y)/(p2.x - p1.x);//find slope of first segment
else m1 = 99999999*Math.signum(p2.y - p1.y); //set it to a really high number just to approximate
//find slope for second line segment
if (p4.x - p3.x != 0)
m2 = (p4.y - p3.y)/(p4.x - p3.x);
else m2 = 99999999*Math.signum(p4.y - p3.y);
// if no slope or line is the same
if (m2 - m1 == 0)
{
p1.y = -p1.y;
p2.y = -p2.y;
p3.y = -p3.y;
p4.y = -p4.y;
return null;//no intersection
}
//find the x value of the intersection
double x = (p1.y*(1+m1) + p3.y*(1+m2)) / (m2 - m1);
//find the y value for plugging in the value we just got into the first line
double y = (p1.y + m1*(x));
//now check to see if the line is inside the segments
double minx = Math.min(p3.x, p4.x);
double miny = Math.min(-p3.y, -p4.y);
double maxx = Math.max(p3.x, p4.x);
double maxy = Math.max(-p3.y, -p4.y);
double minx2 = Math.min(p1.x, p2.x);
double miny2 = Math.min(-p1.y, -p2.y);
double maxx2 = Math.max(p1.x, p2.x);
double maxy2 = Math.max(-p1.y, -p2.y);
//convert them back to the regular axis
p1.y = -p1.y;
p2.y = -p2.y;
p3.y = -p3.y;
p4.y = -p4.y;
// if inside the line segments
if ((x < maxx && x > minx && y > miny && y < maxy) && (x < maxx2 && x > minx2 && y > miny2 && y < maxy2))
{//the line segments intersect
clsPoint intersectionpoint = new clsPoint(x,y,0);
return intersectionpoint;
}
else // they don't intersect
return null;
}[/code][/QUOTE]
IMO you should copy the points if you need to modify them. That way, you don't have to revert them at every possible function-return.
Actually, I fail to see the use of "//first convert the numbers to an inverse y axis coordinate".
For the case that p2.x - p1.x (or p4.x - p3.x) equal 0, you can find the x-coordinate of the intersection pretty easily by finding the point (p2.x, y) (or (p4.x, y)) for the other line. No need to resort to approximation with a "really high number".
I don't recognize the formula you use to "//find the x value of the intersection".
If it is correct though, then your formula for finding the y coordinate is incorrect; it would only work for the case that p1.x = 0.
You should be able to easily find a few methods for finding an intersection-point of two lines via a Google(/Bing/DuckDuckGo/Yahoo/whatevs)-search if you are looking for a different approach.
[QUOTE=Zinayzen;40485374]i think dark souls is copyrighted
don't you try to make a spinoff[/QUOTE]
It's just for a school project.
Phew, fixed it. Thanks.
I'm still infinite looping somewhere, but mostly it's fixed.
Ok, now I am getting the most stupid of errors. I've commented where I get error marking because apparently those arrays are local. When in fact they are not?
[code]class Program
{
static void Main(string[] args)
{
string gameState = "start";
object[] allCards;
object[] playersHand;
object[] compsHand;
while (true)
{
if (gameState == "start")
{
Console.Write("Welcome to Top Trumps!\n\nPlease enter a player name: ");
string playerName = Console.ReadLine();
Console.Clear();
gameState = "create";
}
if (gameState == "create")
{
Card card1 = new Card("Black Knight", 75, 75); //allCards[0] = card1;
Card card2 = new Card("Darkwraith Knight", 60, 60); allCards[1] = card2;
Card card3 = new Card("Undead Mage", 45, 50); allCards[2] = card3;
Card card4 = new Card("Tree Lizard", 30, 40); allCards[3] = card4;
Card card5 = new Card("Serpent Soldier", 55, 55); allCards[4] = card5;
Card card6 = new Card("Anor Londo Guard", 65, 70); allCards[5] = card6;
Card card7 = new Card("Drake", 85, 95); allCards[6] = card7;
Card card8 = new Card("Demonite Demon", 80, 85); allCards[7] = card8;
Card card9 = new Card("Hollow Soldier", 10, 25); allCards[8] = card9;
Card card10 = new Card("Giant Skeleton", 40, 65); allCards[9] = card10;
gameState = "deal";
}
if (gameState == "deal")
{
int i = 0;
foreach (object card in allCards)
{
if (//playersHand.Length <= 4)
{
playersHand[i] = card;
}
else
{
//compsHand[i] = card;
}
i++;
}
}
}
}[/code]
Assigning allCards[0] will throw an exception because you haven't initialised the array, only declared the variable. It will be null by default.
Checking playersHand.Length will throw a NullReferenceException for the same reason.
well shit since people are reading this now might as well
for some reason when I call [URL="http://pastebin.com/UL5zhpuD"]this[/URL] from main it goes into an infinite loop. I see no problems with it, but evidently there's something.
I think the call is something like this:
[cpp]while(menuCommand != EXIT)
{
if(menuCommand == DISPLAY)
{
//Calls Display Function (Complete Movie Listing)
OutputList(oFile, head); //THIS IS THE PROBLEM SOMEHOW
}
else
{
//Call GetAndCheckSearch function
GetAndCheckSearch(menuCommand, stringSearch, intSearch);
//Call search function
SearchFunction(oFile, head, menuCommand, intSearch, stringSearch);
}
//INPUT - This function will receive a command from the user and validates
//the input. Then the valid command will be assigned into the variable.
menuCommand = (Menu)GetAndCheckMenuInput(MAIN_MENU, menuMin, menuMax);
}[/cpp]
The only thing I can think of is MAYBE that if check doesn't work, but it totally should, unless I'm mistaken.
Do you not have access to a debugger? Throw your code into VS and take a look at your locals to see if the variable you think you're getting is getting set, and your call stack will let you know which function is infinitely looping.
I uh...
No, not really. :< Usually when I debug it I just throw in like cout << "*****DEBUG return 1****";
and then throw in three or four so I know what's passing through and what isn't. In this case it's inexplicably not doing anything at all, like it's not even calling the function. But it should be.
well cout's good enough. You sure menuCommand is set to Display at that point?
Yeah, it's just a menu. As long as they don't hit EXIT, it'll either display the full list of movies (originally I thought it was just hanging because the list is like 400 movies long, but i tried it with six movies and it still hung), or it'll go into the other two functions which deal with the other menu options.
there's also a random cin.ignore SOMEWHERE that I can't fucking find, so each time I search I have to hit enter twice.
So the issue is then that the display function, when selected, goes into an infinite loop? Just want to make sure I have an idea what the problem actually is.
That's the thing. I don't think it calls the function correctly. I checked with cout statements (expecting it to loop them) but there was no consol output at all.
Would you mind sending me a working copy of your source code (all of it)?
Give me like ten minutes, but sure.
Hello
Currently I'm working on a program to count the number oddNumberofChildrens in a tree
[code]import java.util.ArrayList;
import java.util.List;
/**
*
* @author J
* Draft
*/
public class Tree
{
private Node root;
/**
Constructs a tree with one node and no children.
@param rootData the data for the root
*/
public Tree(Object rootData)
{
root = new Node();
root.data = rootData;
root.children = new ArrayList<>();
}
/**
Constructs an empty tree, with null for a root.
*/
public Tree()
{
}
/**
Adds a subtree as the last child of the root.
Doesn't work on an empty tree.
*/
public void addSubtree(Tree subtree)
{
root.children.add(subtree.root);
}
public int nodesWithOddNumberChildren()
{
int oddNumbers = 0;
if(root == null)
{
return 0;
}
else if(this.root.children.size() %2 == 1)
{
oddNumbers++;
}
return oddNumbers;
}
class Node
{
public Object data;
public List<Node> children;
public int nodesWithOddNumberChildren()
{
return nodesWithOddNumberChildren();
}
}
}
[/code]
So far I got this as a recursive, but I want to utilize a enhanced for loop
Here are the tester [code]public class TreeDraftTester {
public static void main(String[] args)
{
Tree t1 = new Tree("Tom");
Tree s11 = new Tree("Jerry");
Tree s12 = new Tree("Kevin");
System.out.println(t1.nodesWithOddNumberChildren());
System.out.println("Expected: 0");
t1.addSubtree(s11);
System.out.println(t1.nodesWithOddNumberChildren());
System.out.println("Expected: 1");
t1.addSubtree(s12);
System.out.println(t1.nodesWithOddNumberChildren());
System.out.println("Expected: 0");
System.out.println(new Tree().nodesWithOddNumberChildren());
System.out.println("Expected: 0");
}
}
TreeFinalTester.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author
*/
public class TreeFinalTester
{
public static void main(String[] args)
{
Tree t1 = new Tree("Tom");
Tree s11 = new Tree("Jerry");
Tree s12 = new Tree("Kevin");
Tree s121 = new Tree("Mary");
Tree s111 = new Tree("Sally");
Tree s112 = new Tree("Peggy");
Tree s113 = new Tree("Sue");
s11.addSubtree(s111);
s11.addSubtree(s112);
s11.addSubtree(s113);
s12.addSubtree(s121);
System.out.println(t1.nodesWithOddNumberChildren());
System.out.println("Expected: 0");
t1.addSubtree(s11);
System.out.println(t1.nodesWithOddNumberChildren());
System.out.println("Expected: 2");
t1.addSubtree(s12);
System.out.println(t1.nodesWithOddNumberChildren());
System.out.println("Expected: 2");
}
}
[/code]
Any Suggestions? :O
[QUOTE=Zinayzen;40489398]Give me like ten minutes, but sure.[/QUOTE]
OK, I stepped through your code and here's the deal
Your Menu type is an enum defined like so:
[code]enum Menu
{
EXIT,
OUTPUT,
TITLE,
GENRE,
ACTOR,
YEAR,
RATING,
DISPLAY
};[/code]
Now in your main.cpp you're looking for the menu type to be Display. It seems to me this Display option was added later in your code, because your command checker only searches for 7 possible menu values (0-6):
[IMG]http://puu.sh/2KLGB/e2c7067413.png[/IMG]
Meanwhile, your checker returns a literal integer of which value you want from the enum. Now, you're looking for Display, but Display is Menu(7), which is not accessible due to the nature of your command checker. A simple change to look for Output gives us, at the very least text file output and no infinite loop:
[QUOTE]**************************************************
* PROGRAMMED BY :blah
* STUDENT ID : blah
* CLASS : CS1B - MW 9:00a-10:30a
* ASSIGNMENT #7 : Searching Linked Lists
**************************************************
COMPLETE MOVIE LISTING/n MOVIE # TITLE YEAR RATING GENRE ALT GENRE LEAD ACTOR SUPPORTING ACTOR
-------- ----------------------------------------------- ----- ------- ---------------- ---------------- ------------------- -------------------
1 -842150451-842150451 Sandra Bullock Biography Blind Side, The Quinton Aaron
[/QUOTE]
Although when I change it to accommodate Display as another option, it seems like Output as an option becomes useless and infinite loops there since output doesn't do anything.
[editline]1st May 2013[/editline]
Furthermore your input file had an extra line which fucked over your input. I removed the extra line and it looks like it now outputs a good file
[IMG]http://puu.sh/2KMaV/c868ea5d78.png[/IMG]
Odd thing going on. I get the error "; expected" for every entry into the allCards array after I create them. Any ideas why?
[code]static void Main(string[] args)
{
string gameState = "start";
object[] allCards;
object[] playersHand = { };
object[] compsHand = { };
while (true)
{
if (gameState == "start")
{
Console.Write("Welcome to Top Trumps!\n\nPlease enter a player name: ");
string playerName = Console.ReadLine();
Console.Clear();
gameState = "create";
}
if (gameState == "create")
{
Card card1 = new Card("Black Knight", 75, 75);
Card card2 = new Card("Darkwraith Knight", 60, 60);
Card card3 = new Card("Undead Mage", 45, 50);
Card card4 = new Card("Tree Lizard", 30, 40);
Card card5 = new Card("Serpent Soldier", 55, 55);
Card card6 = new Card("Anor Londo Guard", 65, 70);
Card card7 = new Card("Drake", 85, 95);
Card card8 = new Card("Demonite Demon", 80, 85);
Card card9 = new Card("Hollow Soldier", 10, 25);
Card card10 = new Card("Giant Skeleton", 40, 65);
allCards = { card1, card2, card3, card4, card5, card6, card7, card8, card9, card10 };
Console.WriteLine(allCards.Length + " cards created");
gameState = "deal";
}
}[/code]
I did a bit of some creative changes to your input so the extra lines don't fuck you over.
Here's the new code
[code]MovieNode* InputToList(ifstream& inFileName //Input file
)
{
//Creating new nodes, initializing head to null before assigning memory
//to make sure that memory is available
MovieNode* head;
MovieNode* movPtr;
head = NULL;
movPtr = new MovieNode;
std::string temp;
while(!inFileName.eof() && movPtr != NULL)
{
getline(inFileName, temp); //This sanitizes the input if our entries are more than one line apart
if (!temp.empty()) {
movPtr -> title = temp;
getline(inFileName, movPtr -> leadActor);
getline(inFileName, movPtr -> supActor);
getline(inFileName, movPtr -> genre);
getline(inFileName, movPtr -> altGenre);
inFileName >> movPtr -> year;
inFileName >> movPtr -> rating;
inFileName.ignore(1000,'\n');
getline(inFileName, movPtr -> plot);
movPtr -> next = head;
head = movPtr;
movPtr = new MovieNode;
}
}
delete movPtr; //deallocating pointer/new node when no more information
inFileName.close(); //closes inFile (opened in main)
return head;
}[/code]
For the record, using !ifstream.eof() is generally a much better boolean check than using ifstream as a literal boolean.
InputFile looks like this:
[QUOTE]Zodiac
Jake Gyllenhaal
Mark Ruffalo
Drama
Crime
2007
8
Based on the Robert Graysmith books about the real life notorious Zodiac, a serial killer who terrorized San Francisco with a string of seemingly random murders during
the 1960s and 1970s.
You Don't Mess with the Zohan
Adam Sandler
John Turturro
Comedy
Action
2008
6
An Israeli Special Forces Soldier fakes his death so he can re-emerge in New York City as a hair stylist.[/QUOTE]
Yet your output still is correct with my new code.
Ahh fuck my merge :C
[QUOTE=pyschomc;40489547]Hello
Currently I'm working on a program to count the number oddNumberofChildrens in a tree
[code]//code[/code]
So far I got this as a recursive, but I want to utilize a enhanced for loop
Here are the tester [code]//code[/code]
Any Suggestions? :O[/QUOTE]
What do you mean by enhanced for loop? You'll have to be a bit more specific.
[QUOTE=ZeekyHBomb;40489979]What do you mean by enhanced for loop? You'll have to be a bit more specific.[/QUOTE]
I mean
Would a enhanced for loop would sufficed?
The current code completes the first tester cases, and the first case of the second tester, but doesn't pass the rest of the tester.
[QUOTE=ZeekyHBomb;40489979]What do you mean by enhanced for loop? You'll have to be a bit more specific.[/QUOTE]
I think he means the Java equivalent of
[code]
foreach (int i in intArray)
{
//blah
}[/code]
Correct me if that's not the purpose of an enhanced for loop (I'm a C# guy.)
[QUOTE=Protocol7;40490128]I think he means the Java equivalent of
[code]
foreach (int i in intArray)
{
//blah
}[/code]
Correct me if that's not the purpose of an enhanced for loop (I'm a C# guy.)[/QUOTE]
It's pretty much similiar to that.
I just need some tips on what to do Haha , I've been at it for hours.
[QUOTE=Protocol7;40489957]I did a bit of some creative changes to your input so the extra lines don't fuck you over.
Here's the new code
[code]MovieNode* InputToList(ifstream& inFileName //Input file
)
{
//Creating new nodes, initializing head to null before assigning memory
//to make sure that memory is available
MovieNode* head;
MovieNode* movPtr;
head = NULL;
movPtr = new MovieNode;
std::string temp;
while(!inFileName.eof() && movPtr != NULL)
{
getline(inFileName, temp); //This sanitizes the input if our entries are more than one line apart
if (!temp.empty()) {
movPtr -> title = temp;
getline(inFileName, movPtr -> leadActor);
getline(inFileName, movPtr -> supActor);
getline(inFileName, movPtr -> genre);
getline(inFileName, movPtr -> altGenre);
inFileName >> movPtr -> year;
inFileName >> movPtr -> rating;
inFileName.ignore(1000,'\n');
getline(inFileName, movPtr -> plot);
movPtr -> next = head;
head = movPtr;
movPtr = new MovieNode;
}
}
delete movPtr; //deallocating pointer/new node when no more information
inFileName.close(); //closes inFile (opened in main)
return head;
}[/code]
For the record, using !ifstream.eof() is generally a much better boolean check than using ifstream as a literal boolean.
InputFile looks like this:
Yet your output still is correct with my new code.
Ahh fuck my merge :C[/QUOTE]
My fix wasn't quite that fancy, but it worked. Somehow.
I do have a couple more errors but I already lost points for turning it in late so I'd rather not risk it any more. fuck it.
this is a shit day for me in general. :(
[QUOTE=pyschomc;40490094]I mean
Would a enhanced for loop would sufficed?
The current code completes the first tester cases, and the first case of the second tester, but doesn't pass the rest of the tester.[/QUOTE]
Oh, so this is your complete code?
Well in that case the issue is not a recursive approach, but your solution only regards the root-node and no child-nodes; you need to check for an uneven number of children there, too.
[QUOTE=pyschomc;40490170]It's pretty much similiar to that.
I just need some tips on what to do Haha , I've been at it for hours.[/QUOTE]
Is this what your program is returning?
[IMG]http://puu.sh/2KOKZ/0972193be4.png[/IMG]
I don't have a Java DE so I C++ized everything you had, want to make sure I'm getting the same results you are.
Oh whoops I fucked something up, hold on.
[QUOTE=ZeekyHBomb;40490395]Oh, so this is your complete code?
Well in that case the issue is not a recursive approach, but your solution only regards the root-node and no child-nodes; you need to check for an uneven number of children there, too.[/QUOTE]
True As you can see in my draft
[code] base case is if(root == null) {return 0;} else if (this.root.children.size() %2 == 1) {counter ++); return counter;[/code]
As this just checks the basic 1 and 0. Haha.
I heard stacks might be useful ,but I'm not too sure.
Sorry, you need to Log In to post a reply to this thread.