Hello.
I am a beginner and I have this code that has been killing me.
Any and all help is appreciated.
Its a cipher and for some reason it won't work.
It opens and asks for user input but doesn't execute anything correctly.
It took me a minute to realize, but line 7, char cipher (char);, is the function prototype for the cipher function. You should probably put that before the main function. It works the way it is, but like I said, it's a bit confusing (at least it was to me) to try and read it.
It opens and asks for user input but doesn't execute anything correctly.
Can you elaborate on this a little bit (what exactly happens?).
I think you may be having issues with mixing std::cin and std::getline (maybe one of the more experienced members can explain why that is because I'm not confident enough with my understanding to even try explaining it). For now, try adding cin.get() after each cin>> statement, and see if that helps.
Firstly, you should only close the files once you're done with them, so after the loop.
Secondly, you're returning in the loop, return will just simply exit the function regardless of where you are (in this case it will exit main, closing the program).
Finally, a more common while condition while reading a file is while(!infile.eof()) // continue while you have not reached the end of the file
It's wrong isn't exactly the most helpful statement, I've been away for a while so I've certainly forgotten parts. What would you suggest being "right" then? while(infile.is_open())
and checking for eof and closing in the loop? while(infile.getline(x,y)
or as suggested above by DTSCode?
Or something else?