### error: exited with non-zero status

i keep getting this error on my code and i can't figure out why. can someone please explain?

if the user inputs: 4 3 4 4 7
it should output the message: Three of a kind but instead its throwing out an error: exited with non-zero status. Not sure where I went wrong.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152`` ``````#include using namespace std; // function prototype bool containsThreeOfaKind(int hand[]); // main function int main() { // declaring the user array int card[5] = {}; // ask user to input five numeric cards between 2-9 cout << "Enter five numeric cards, no face cards. Use 2-9" << endl; for (int i = 0; i < 5; i++) { cout << "Card " << i + 1 << ": "; cin >> card[i]; } if (containsThreeOfaKind(card)) { cout << "Three of a kind" << endl; } return 0; } // function definition bool containsThreeOfaKind(int hand[]) { bool threeOfaKind = false; int counter = 0; int triple; for (int i = 0; i < 5; i++) { for (int j = i + 1; j < 5; j++) { if (hand[i] == hand[j] && counter < 1) { triple = hand[i]; } else if (hand[i] == hand[j] && hand[i] == triple) { counter++; threeOfaKind = true; } } } return threeOfaKind; }``````
Last edited on
Hi,

I ran the code and had no output but normal termination (returned 0)

There is a logic problem in your code though, time to break out the debugger :+) I reckon I know what the problem is, but if you learn how to use a debugger you will discover it yourself, and learn how massively important the debugger is.

Hopefully your IDE has a GUI debugger in it. You should be able to set break points, a watch-list of variables and their values. Step through the code 1 line at a time, keep an eye on the values and deduce where it all goes wrong.

If you r IDE does not have a debugger in it, or you code with an editor only, then there are command line versions such gdb.

Good Luck !!
Topic archived. No new replies allowed.