I got the questionairre problem.

I was trying to fill the answers from the 20 questions and output the file as results.txt, but it only shows the answers of 19 questions.

And when I fill up all the answers, the total score shows 0.

The scores for each question (except q4, q8, q12, and q16):
0 - not at all
1 - a little
2 - some
3 - a lot

The scores for q4, q8, q12, and q16:
3 - not at all
2 - a little
1 - some
0 - a lot

#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;

// Declaration of file stream variables
ofstream outfile; // Output file stream variable

int answer(char ans, int naa, int aL, int S, int aLot)
{
    if (ans == 'a')
    {
        naa++;
    }
    else if (ans == 'b')
    {
        aL++;
    }
    else if (ans == 'c')
    {
        S++;
    }
    else if (ans == 'd')
    {
        aLot++;
    }

    return naa, aL, S, aLot;
}

int R_answer(char ans, int R_naa, int R_aL, int R_S, int R_aLot)
{
    if (ans == 'a')
    {
        R_naa++;
    }
    else if (ans == 'b')
    {
        R_aL++;
    }
    else if (ans == 'c')
    {
        R_S++;
    }
    else if (ans == 'd')
    {
        R_aLot++;
    }

    return R_naa, R_aL, R_S, R_aLot;
}

int scoring(int naa, int aL, int S, int aLot, int R_naa, int R_aL, int R_S, int R_aLot)
{
    int totalScore = 0; // Total score

    totalScore = (3 * aLot) + (2 * S) + (1 * aL) + (0 * naa) + (0 * R_aLot) + (1 * R_S) + (2 * R_aL) + (3 * R_naa);

    cout << "Your score: " << totalScore << " / 60" << endl;

    return totalScore;
}

int main()
{
    int naa = 0; // Number of "Not at all"s (except questions 4, 8, 12, and 16)
    int aL = 0; // Number of "A Little"s (except questions 4, 8, 12, and 16)
    int S = 0; // Number of "Some"s (except questions 4, 8, 12, and 16)
    int aLot = 0; // Number of "A Lot"s (except questions 4, 8, 12, and 16)

    int R_naa = 0; // Number of "Not at all"s (for questions 4, 8, 12, and 16)
    int R_aL = 0; // Number of "A Little"s (for questions 4, 8, 12, and 16)
    int R_S = 0; // Number of "Some"s (for questions 4, 8, 12, and 16)
    int R_aLot = 0; // Number of "A Lot"s (for questions 4, 8, 12, and 16)

    int i = 0; // Counter
    int ts; // Total score from scoring class

    char ans = ' '; // MCQ answer

    outfile.open("results.txt"); // Creating the results text file

    cout << "INSTUCTIONS: " << endl;
    cout << "Below is a list of the ways you might have felt or acted. Please check how MUCH you have felt this way during the PAST WEEK" << endl << endl;

    cout << "1. I was bothered by things that don't usually bother me." << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl <<endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    answer(ans, naa, aL, S, aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "2. I did not feel like eating, I wasn't very hungry." << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    answer(ans, naa, aL, S, aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "3. I wasn't able to feel happy, even when my family or friends tried to help me feel better." << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    answer(ans, naa, aL, S, aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "4. I felt like I was just as good as other kids." << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    R_answer(ans, R_naa, R_aL, R_S, R_aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "5. I felt like I couldn't pay attention to what I was doing." << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');


    answer(ans, naa, aL, S, aLot);

    system("cls"); // Clear screen

    cout << "6. I felt down and unhappy" << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    answer(ans, naa, aL, S, aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "7. I felt like I was too tired to do things" << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    answer(ans, naa, aL, S, aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "8. I felt like something good was going to happen" << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    R_answer(ans, R_naa, R_aL, R_S, R_aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "9. I felt like things I did before didn't work out right." << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    answer(ans, naa, aL, S, aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "10. I felt scared." << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    answer(ans, naa, aL, S, aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "11. I didn't sleep as well as I usually sleep." << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    answer(ans, naa, aL, S, aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "12. I was happy." << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    R_answer(ans, R_naa, R_aL, R_S, R_aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "13. I was more quiet than usual." << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    answer(ans, naa, aL, S, aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "14. I felt lonely, like I didn't have any friends." << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    answer(ans, naa, aL, S, aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "15. I felt like kids I know were not friendly or that they didn't want to be with me." << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    answer(ans, naa, aL, S, aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "16. I had a good time." << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    R_answer(ans, R_naa, R_aL, R_S, R_aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "17. I felt like crying." << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    answer(ans, naa, aL, S, aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "18. I felt sad." << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    answer(ans, naa, aL, S, aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "19. I felt people didn't like me." << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');

    answer(ans, naa, aL, S, aLot);

    i++;
    outfile << i << ". " << ans << endl;

    system("cls"); // Clear screen

    cout << "20. It was hard to get started doing things." << endl;
    cout << "\tA. Not at all" << endl;
    cout << "\tB. A Little" << endl;
    cout << "\tC. Some" << endl;
    cout << "\tD. A Lot" << endl << endl;

    do
    {
        cout << "Your answer: ";
        cin >> ans;

        ans = tolower(ans);
    } while (ans != 'a' && ans != 'b' && ans != 'c' && ans != 'd');;

    answer(ans, naa, aL, S, aLot);

    i++;
    outfile << i << ". " << ans << endl << endl;

    system("cls"); // Clear screen

    ts = scoring(naa, aL, S, aLot, R_naa, R_aL, R_S, R_aLot);

    outfile << "Your score: " << ts << " / 60" << endl;
    outfile.close();
    system("pause");
    return 0;
}

return naa, aL, S, aLot;

You can only return ONE value. Just ONE.

As it happens, you're not even using the returned value.

You need to learn about the following:

returning values from functions
passing by reference

To continue on Moschops post, the only way to return multiple values from a function is to put them in a structure or object, and then return that. This will require modifying the signature of the function accordingly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.