Computer Science Canada Stuck on a problem, Quick fix |
Author: | Panphobia [ Sat Dec 08, 2012 8:50 pm ] | ||||
Post subject: | Stuck on a problem, Quick fix | ||||
I have been learning c++ and I have been looking over the old dwite questions and solving them in c++ for practise and such, I have a current question im finishing from the new round 2 dwite http://dwite.org/questions/magic_trick.html , i know how to solve it, just a little compiling error, if someone could point me in the right direction that would be nice
|
Author: | Insectoid [ Sat Dec 08, 2012 10:03 pm ] |
Post subject: | RE:Stuck on a problem, Quick fix |
Read the error. What does it say? "no match for call to ?(std::set<int>)" on line 30. Does 'set' exist? |
Author: | Panphobia [ Sat Dec 08, 2012 10:37 pm ] |
Post subject: | RE:Stuck on a problem, Quick fix |
how does it not exist, and how do you get a certain value in a set, im checking the c++ api and it doesnt work? |
Author: | Insectoid [ Sat Dec 08, 2012 10:54 pm ] |
Post subject: | RE:Stuck on a problem, Quick fix |
Ah. Well, after perusing the documentation, I've discovered that you're using it wrong. You do not retrieve elements from a set with parentheses; you need to use the find() function. |
Author: | Panphobia [ Sat Dec 08, 2012 11:03 pm ] | ||||
Post subject: | Re: Stuck on a problem, Quick fix | ||||
I actually did but it doesnt work, right after i tried lol. I am thinking about changing it to a vector and when i did this is what happened, can you see anything wrong?
|
Author: | Panphobia [ Sun Dec 09, 2012 2:33 am ] | ||||
Post subject: | Re: Stuck on a problem, Quick fix | ||||
still havent solved the question up there ^, if anyone could help that would be great but i am also having some trouble converting my recursive knowledge from java to c++, i think everyone starts off with the factorial recursive problem but here is my code for factorial in recursion
|
Author: | Insectoid [ Sun Dec 09, 2012 8:38 am ] |
Post subject: | RE:Stuck on a problem, Quick fix |
The erase() function does not take an int as a parameter. It takes an iterator. I recommend you learn about pointers. They're everywhere in C++, and you won't get far without them. As for your recursion function, it works just fine on my computer. Depending on your system, the segfault may just be due to calculating far too large of a number. Mine returns 0 when it gets too big. |
Author: | Panphobia [ Sun Dec 09, 2012 12:17 pm ] |
Post subject: | RE:Stuck on a problem, Quick fix |
I'm calculating 5!.... |
Author: | Insectoid [ Sun Dec 09, 2012 12:31 pm ] |
Post subject: | RE:Stuck on a problem, Quick fix |
Then the issue is likely somewhere else in your code. A segmentation fault means you're accessing RAM that you aren't allowed to or that does not exist. |
Author: | Panphobia [ Sun Dec 09, 2012 12:40 pm ] | ||
Post subject: | Re: Stuck on a problem, Quick fix | ||
I made a little test of input output etc, here is the rest of my code...
|
Author: | Insectoid [ Sun Dec 09, 2012 12:47 pm ] |
Post subject: | RE:Stuck on a problem, Quick fix |
What is the value of c at line 24? What happens if you pass that value to factorial()? |
Author: | Panphobia [ Sun Dec 09, 2012 1:03 pm ] |
Post subject: | RE:Stuck on a problem, Quick fix |
oh shit >.< you just made me look at the entire thing LOOOOOOOOOL |
Author: | Panphobia [ Sun Dec 09, 2012 3:21 pm ] | ||
Post subject: | Re: Stuck on a problem, Quick fix | ||
Am I doing something wrong, because I kind of now copied someone elses answer on the dwite and they got 5/5 but it will not run and print out the answers, here is the code, and it just stops when i run it, it does not even go
|
Author: | Insectoid [ Sun Dec 09, 2012 6:21 pm ] |
Post subject: | RE:Stuck on a problem, Quick fix |
Runs fine for me. |
Author: | Panphobia [ Sun Dec 09, 2012 6:28 pm ] |
Post subject: | RE:Stuck on a problem, Quick fix |
Am I compiling wrong???????? Because I am compiling through the command line like, g++ cppTest.cpp -o test and then ./test and it isnt printing ANYTHING |