I am trying to make a Go Fish program in C++, and am currently a student who is trying to better my knowledge of this language on my own. Actually I am done with my C++ classes and will be moving on to Java next quarter.
My code is below, all I am trying to do is output the vector so that I can verify that the shuffle works. When I run the program, then select 1 to Play, the program will display the first 20 elements of the vector then a window pops up saying "GoFish.exe has stopped running" and gives me 3 options: search online for a solution, close the program, or debug the program. I cannot debug, because I haven't learned how to implement that. By that I mean, I can read what it says but I do not understand what it means.
for (int i = 0; i < 21; i++)
{
cout << deck[i] << endl;
//system("PAUSE");
}
}while (selection != 2);//end do while
return 0;
}
So, I opened a new project and just put this in it to test my FOR loop to make sure my logic was right. This code worked fine, so I was still stumped.
#include <iostream>
using namespace std;
int main()
{
for( int = 0; i < 21; i++)
{
cout << i << endl;
}
return 0;
}
I also had just a WHILE loop, and changed it to the DO WHILE loop because I thought maybe the PRE/POST test had something to do with it. Didn't change the error.
And lastly I changed the loopContinuationCondition to i < 21. Originally I had for ( int i = 0; i < deck.size(); i++) and it created an infinite loop without any errors. That is why I put the "PAUSE" line in, so I could stop it. So I decided to use i < 21 since I have 20 elements in the vector. Now I am getting the error I am asking about.
The code I have written is by no means proper in a "real world" environment, so please excuse my lack of work experience. It is not finished, I just like to constantly test along the way.
You're... moving ON to Java? Weird system... I would've thought Java first, then C++.
Anyways, as firedraco said, it's your while loop. You probably want to put your selection menu inside of the loop, since that would be the easiest solution to the problem. It might not be the most elegant solution, but since you're just testing to see if it works, it doesn't matter.
firedraco:
I understand what you are saying, and I didn't even think about that line being inside of the loop.
NGen:
With the selection variable - I was just following the "format" of other programs I have written.
I have learned Python, VB .net, C++, and SQL. It also seemed odd to me the order in which we learned them. Everyone besides me hated C++, and barely passed the courses. However we only did one program using vectors, and I want to fully understand their capabilities. So thanks again for help with my program, and I will probably need more help along the way.
If you're still reading this, I suggest you ask your teacher to rethink the order in which they teach things. VB... I don't even know why they would teach that. It's so pointless, and the syntax doesn't resemble any other languages. It's about as valuable as MUMPS (the language, look it up... not fun). Python isn't exactly 'pointless', but the syntax issue is the same (as far as I know, I only took a quick look at it and thought "No. Just... No."). Java and C++ are similar enough, but Java is simpler, the main difference syntax-wise being pointers and templates. I would think that SQL would be last.