I have spent way too much time trying to get my first assignment correct for my C++ programming class. I have put in a ton of work, but haven't successfully got the program to execute and finish without stopping and throwing an error. The program is to play a game of war, where both players are dealt 26 cards alternating from one player to the other. There has to be 4 vectors, and I have them listed below as the card pile and the battle deck for each player. Where the problem seems to be lying is when the test checks to see if the battle card is the same, then drawing two more cards and comparing the third card in the battle decks. If anyone can give me any advice on this I would appreciate it. Programming doesn't come naturally to me, and I have to really work hard to learn it, and this assignment has already received a zero for not being turned in on time. So your not helping me get the grade, I just need help understanding it.
I just figured how to post this in code format above, hope this helps. I'm working on it right now, hoping someone might be on at this time of night to assist in anyway possible.
When you remove the first card, the second card becomes the first. Doing playerA_cards.erase(playerA_cards.begin());
three times is I believe what you meant to do.
// if (argc < 1) // Note: correct argc does not guarantee correct argv[] contents
if (argc < 2 ) // argc will be at least 1, argv[0] is always passed
Line 100:
1 2
// else if (playerA_battleDeck[0] = playerB_battleDeck[0])
elseif (playerA_battleDeck[0] == playerB_battleDeck[0]) // you did mean ==, didn't you?
Line 179:
1 2
// j+2;
j += 2 ; // did you intend this?
Line 194:
1 2 3
if (playerA_cards.size() == 0 or playerB_cards.size() == 0)
// not wrong, but this is usually written as:
// if (playerA_cards.size() == 0 || playerB_cards.size() == 0
Now run your program (after making the corrections) and try to debug it.
A 200+ line main()!
Do you know how to write functions?
I do, but this assignment was to not use functions. Let me look over your post for a minute and see what I can do. On the original code I posted earlier there were some issues I'm working on already, like the one Yay295 commented on.
Thanks for the pointers on this Yay295 and JLBorges. I made sure I fixed my silly mistakes, and JLBorges the points you made were correct, I did mean
if (argc < 2 )
and I did mean "==" and "j+=2"
Also, I made sure I sticked to using "||" instead of "or" for viewability.
The problem seemed to come from me not having enough conditional statements. By putting more checks on the program it functioned. I had to add in more if statements to check for different conditions.
I understand that this would be much easier if I was using functions, but the assignment was to not use functions. Once again, thanks for the help.