![]() |
|
#1
|
|||
|
|||
prime factors with stackI have to to write a program that uses a stack to print the prime factors of a positive integer in descending order.
I compiled this and it has alot of errors. Any advice? I am not sure how to put the codes in special formatted windows for you to view. Thank you CPP / C++ / C Code:
program test CPP / C++ / C Code:
Last edited by cable_guy_67 : 16-Apr-2006 at 07:21.
Reason: Please enclose c++ code in [c++] ... [/c++] tags
|
|||
|
#2
|
|||
|
|||
Re: prime factors with stackQuote:
For a better chance of getting meaningful help without getting a lot of information about things that you aren't supposed to do (and, therefore, wasting your time giving us a better explanation spread out over several posts): State the assignment more precisely: Does the assignment include the requirement that you write your own class for a stack? Or can you use standard template library classes? Or what? Quote:
1. Post the errors. Paste the exact errors into your post (do not paraphrase). Post all compiler messages (warnings as well as errors). If there are hundreds and hundreds of errors, then post the first 20 or so. 2. Tell us what compiler/operating system you are using. Sometimes it makes a difference to people who are trying to help. Quote:
Put [c] before the first line of code and put [/c] after the last line of code, as detailed in Guidlines for posting requests... Regards, Dave |
|
#3
|
|||
|
|||
Re: prime factors with stackThank you for your help. This assignment requests that we create our own Template<classType> one has to be myStack header.h and myStack testprogrm.
The program we use is C++ bloodshed. Below are some compiler errors. myStacktestprogram.cpp:11:21: myStack.h: No such file or directory myStacktestprogram.cpp: In function `int main()': myStacktestprogram.cpp:17: error: `stackType' undeclared (first use this function) myStacktestprogram.cpp:17: error: (Each undeclared identifier is reported only once for each function it appears in.) myStacktestprogram.cpp:17: error: expected primary-expression before "int" myStacktestprogram.cpp:17: error: expected `;' before "int" myStacktestprogram.cpp:18: error: expected primary-expression before "int" myStacktestprogram.cpp:18: error: expected `;' before "int" myStacktestprogram.cpp:20: error: `stack1' undeclared (first use this function) myStacktestprogram.cpp:40: error: `stack2' undeclared (first use this function) myStacktestprogram.cpp:49: error: `num' undeclared (first use this function) myStacktestprogram.cpp:53: error: `push' undeclared (first use this function) myStacktestprogram.cpp:53: error: expected `;' before "fact" myStacktestprogram.cpp:53: error: expected primary-expression before ')' token myStacktestprogram.cpp:53: error: expected `;' before ')' token myStacktestprogram.cpp:61: error: `clrscr' undeclared (first use this function) myStacktestprogram.cpp:62: error: invalid operands of types `int __complex__' and `int' to binary `operator<' make.exe: *** [myStacktestprogram.o] Error 1 |
|
#4
|
|||
|
|||
Re: prime factors with stackQuote:
This is pretty important: the compiler can't find your header file! Everything is lost until you tell it. Add the header file to the project and try again. I'm not running dev-c++ just now, so I can't give details, but I know that there others nearby who might be able to help you with the project settings if you need it. Now, after it finds the header, there may be other errors, but we'll take the next step when we get that far. Try to see exactly what the compiler tells you for each one. If you can't figure it out, you can ask. The important step is to look at the messages: start with the very first one. If you can find and fix the problem that caused it, then some (or, maybe even all) of the others may go away. Of course, once you fix one problem, the compiler may find other things that it didn't even see before. Find-fix as you go. Think of it as an adventure. Once the errors have been silenced, then begins the real adventure: testing/debugging. But you have to get the blooming thing to compile first (and, sometimes that's the hardest part for people just getting started). Regards, Dave |
|
#5
|
|||
|
|||
Re: prime factors with stackOkay I found the header file would be #include <stack>. It is not showing the error: myStacktestprogram.cpp:11:21: myStack.h: No such file or directory
anymore. I am showing this errors which are almost the sames errors as before. Most the errors codes shown below are already declared like the original codes I posted here. Can you still help? myStacktestprogram.cpp: In function `int main()': myStacktestprogram.cpp:22: error: `stackType' undeclared (first use this function) myStacktestprogram.cpp:22: error: (Each undeclared identifier is reported only once for each function it appears in.) myStacktestprogram.cpp:22: error: expected primary-expression before "int" myStacktestprogram.cpp:22: error: expected `;' before "int" myStacktestprogram.cpp:23: error: expected primary-expression before "int" myStacktestprogram.cpp:23: error: expected `;' before "int" myStacktestprogram.cpp:25: error: `stack1' undeclared (first use this function) myStacktestprogram.cpp:45: error: `stack2' undeclared (first use this function) make.exe: *** [myStacktestprogram.o] Error 1 |
|
#6
|
|||
|
|||
Re: prime factors with stackQuote:
Is that because you took out the statement that included it? The program must include myStack.h in order to be able create any objects from the class "stackType". You don't need to include the standard library header <stack>, since you won't be using anything from there. So: you still should add the file myStack.h to your project before you compile it. It should be in your project files, and it has to be #included in your main program file. (And it should be in the same directory as your main program cpp file.) Quote:
Go back to your original source files (the cpp file has #include "myStack" in it) and, in the dev-c++ interface, add myStack.h to the project files: In the project window, right-click on the "Project" icon and select "add to project". You should get a window that shows your header file in addition to your cpp file. Select the header file so that both it and the cpp file are in the project. Then try to compile. You will get errors (but not the same as before). Regards, Dave |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| New to OO need advice | weeb0 | C++ Forum | 2 | 26-Jan-2006 09:03 |
| Advice on Programming General | virtualconcepts | MySQL / PHP Forum | 3 | 01-Aug-2005 21:46 |
| Need advice on a disturbing problem | JUNK KED | Open Discussion Forum | 6 | 31-Mar-2005 14:51 |
| I need some anti-hacking advice! | slayerbeatch | Open Discussion Forum | 6 | 16-Feb-2005 17:59 |
| HELP! I need advice | jmb | Web Design Forum | 3 | 25-Mar-2003 04:21 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The