The code below is for my project in my subject which is c++. The code works fine but it seems like the output is inconsistent and weird. Would you please help me think of a solution to this error? I tried to research and read books about this issue but still its not clear for me. Thank you in advance


#include "stdafx.h"
#include <iostream>
using namespace std;

int ctr, x, y, z;

//Questions expressed as functions
void q1(), q2(), q3(), q4(), q5(), q6(), q7(), q8(), q9(), q10(), q11(), q12(), q13(), q14(), q15(), q16(), q17(), q18(), q19();
void count(); //Function that records the answers submitted

int main ()
{
x = 0; y = 0; z = 0;
cout << "**Happiness Test**" << endl << endl
<< "A series of conditions will be posted. State the degree of relevance: \n"
<< "1 - Never \n"
<< "2 - Often \n"
<< "3 - Always \n" << endl << endl;
q1(); //Starts presenting questions
q2();
q3();
q4();
q5();
q6();
q7();
q8();
q9();
q10();
q11();
q12();
q13();
q14();
q15();
q16();
q17();
q18();
q19();

if (x > y && y > z)
cout << "You are sorrowful as of now.";
else if (x > z && z > y)
cout << "You are an unhappy person.";
else if (y > x && x > z)
cout << "You are pleased as a person.";
else if (y > z && z > x)
cout << "You are a cheerful person.";
else if (z > x && x > y)
cout << "You are a joyous person.";
else
cout << "You are definitely a happy person.";

cin.ignore();cin.ignore(); //To avoid rapid application termination
}

//Function definitions
void q1()
{
cout << "I smile everyday." << endl;
do { //Re-evaluates if submitted number is out of bounds
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count (); //Records the answer submitted
}
//The remaining q_ functions are similar
void q2()
{
cout << "I don't overthink things." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void q3()
{
cout << "I am optimistic." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void q4()
{
cout << "I laugh hard." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void q5()
{
cout << "I have a lot of friends that make me happy." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void q6()
{
cout << "I have a good sense of humor." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void q7()
{
cout << "I am a happy-go-lucky person." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void q8()
{
cout << "I have a positive outlook in life." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void q9()
{
cout << "I have a complete family." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void q10()
{
cout << "I feel loved by the people around me." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void q11()
{
cout << "I have a good disposition in life." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void q12()
{
cout << "I cry easily." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void q13()
{
cout << "I can be happy even though I'm surrounded with problems." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void q14()
{
cout << "I have nothing else to wish for." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void q15()
{
cout << "I am a bubbly person." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void q16()
{
cout << "I make others happy." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void q17()
{
cout << "I am oozing with self-confidence." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void q18()
{
cout << "I have a high self-esteem." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void q19()
{
cout << "I consider myself fortunate." << endl;
do {
cin >> ctr;
if (ctr < 1 || ctr > 3)
cout << "Number out of bounds. Please re-enter your answer." << endl;
} while (ctr < 1 || ctr > 3);
cout << endl;
count ();
}

void count() //Records the answers entered where x: never, y: often, z: always
{
if (ctr == 1)
x++;
else if (ctr == 2)
y++;
else if (ctr == 3)
z++;
}