| keikepono (7) | |||
So I am trying to make a madlibs program that will ask for a file and open it, read it, and ask the user for input, then input the words in the story and display them.
so I am in need of guidance for my play again option. I need to make it so if they choose 'y' that it will run the program again I have tried: if(choice == 'y') main(); which I was hoping would just run main again to run the entire program again but that does not work, it just says error reading file(that user inputs) and stops there. | |||
|
|
|||
| maddogg2222 (3) | |||||
|
EDIT:: Ohh wait nvm What you need to do is put
inside your if statment right before you recall main(); so for example:
| |||||
|
Last edited on
|
|||||
| keikepono (7) | |||||
so I tried this:
the first one did repeat the program, but it does this:
The error reading file should not happen because later in the program it reads the file just fine and ouputs the story correctly. | |||||
|
|
|||||
| TheIdeasMan (1753) | ||
Here is a link to some info i provided for someone else:
Btw, Never ever call main() - not ever !! Nor should you use goto's (just in case you are tempted) There is also no need to declare the main function. Always use loops to achieve what you want. HTH | ||
|
|
||
| keikepono (7) | ||||
|
to maddog: it WORKED - thanks so much to TheIdeasMan: I can see why in terms of knowing nothing about c++ why you would not want to call main() into anything, but I want to know why not? not to be rude, im just not sure why there would be a problem with that and I want to learn why. Also I declared main to see if it would solve anything (it didnt) and forgot to take it out, thanks for pointing that out! as to my final problem, I have those case statements in there to determine things for example: in the file we are given the story which has words in it, but when there are words that we need to replace it looks like this <{> <adjective> <}> so I have the logic to remove the first set of <{> and replace it with a " and a space and the last set with a space and " so it looks like this: " <adjective> " then the logic goes through and says remove the < and > and bring the " in closer and capitalize the first letter and add a tab so it looks like this: Adjective: then the enter what they want in there, for this example the enter "happy" so my program changes Adjective: to "happy" and displays that like the example below however it messes with some other things
there are space before those new lines and there should not be. I thought it was this section of the program:
but that just messes up another part of the program as well so I thought about adding in something that will determine if it is the end of line or file because that's when it happens, but i cant quite get the logic right, here is what i am trying: if "end of line" cin.ignore(); im not sure if that would work or not but that is what I am trying to do... any thoughts? | ||||
|
|
||||
| TheIdeasMan (1753) | ||||||
It also creates a new main function on the stack, then keeps doing that again and again until you run out of memory. Did you set up your loops the way I mentioned in the link I provided? I think this is a much better solution than was provided by maddog , IMO, because it is much clearer & easy to follow.
What did you mean by that ? By far the easiest way to fix problems like this, is to use the debugger. Hope this helps. | ||||||
|
|
||||||
| keikepono (7) | ||
when I change it around, it will delete the space between the " and the next letter/symbol and I need it there so it would not run together like this "happy"next word instead of "happy"-space-next word. apparently I can't do this either: case '!"': break; I was hoping that would get rid of the space and immediately go to the default. but on second thought maybe thats what puts the space in the first place. not sure ill go look into it. | ||
|
|
||