Description: Friend’s finder. You load a data file first. Then you answer 10 questions. The answers will be saved in an array. The data in file are several arrays answered by other users. You need to compare the answers with other users and calculate the similarity. After that it will show your best 1Emphasized Text Here0 matches on the monitor.

I am able to read the file but I am having major issues with assigning the values in the file into several arrays. Every time I run the program it fails it may be a loop problem but I'm not completely sure.

This is my data file: Answers2.txt

Howard Lacrosse 19 Engineering LTU Belleville Green Pizza African Male
Zaid Tennis 19 Engineering LTU Dearborn Pink Soup Arab Male
Yat Basketball 19 Civil LTU Belleville Green Rice Chinese Male
Stephanie Yoga 24 Architect Central southfield Blue Chicken Asian Female
Adam Soccer 19 GameArt LTU Ypsilanti Red Chicken Caucasian Male
Ashley Karate 18 Media LTU Westland Magenta Oranges Caucasian Female
Hentrell Basketball 19 GameArt LTU Chicago Black Chicken African Male
Corey Baseball 24 PreDental LTU Chicago Black Pizza Caucasian Male
Topanga Golf 25 Physics LTU Dearborn Pink Soup Caucasian Female
Katelyn Softball 20 History GrandValley Warren Blue Oranges Caucasian Female

The 10 questions if you cannot tell:
What is the person's name?
What is their favorite Sport?
How old is said person?
What Major is said person?
What School does said person attend?
Where is said person From?
What is said person's favorite color?
What is said person's favorite food?
What race is said person?
What sex is said person

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdlib>
using namespace std;

void outputLine(string [], string [], int [], string [],  string [],  string [],  string [],  string [], string [], string []);

int main()
{
    ifstream inClientFile("Answers2.txt", ios::in);

    if(!inClientFile)
    {
        cerr <<"FIle could not be opened" <<endl;
        exit(1);
    }

    string name[9];
    string sports[9];
    int age[9];
    string major[9];
    string school[9];
    string city[9];
    string color[9];
    string food[9];
    string race[9];
    string sex[9];

    for(int i = 0; i <= 9; i++)
    {
    inClientFile >> name[i] >> sports[i] >> age[i] >> major[i] >> school[i] >> city[i] >> color[i] >> food[i] >> race[i] >> sex[i];

    outputLine(name, sports, age, major, school, city, color, food, race, sex);
    }
}

void outputLine(string name[9], string sports[9], int age[9], string major[9],  string school[9], string city[9], string color[9], string food[9], string race[9], string sex[9])
{   
        cout <<left<< setw(7) << name[9] << setw(7) << sports[9] << setw(7) << age[9] << setw(7) << major[9] << setw(7) << school[9] << setw(7) << city[9] << setw(7) << color[9] << setw(7) << food[9] << setw(7) << race[9] << setw(7) << setprecision(2) << right << sex[9]<<endl;
}

You need to start over from scratch. Lines 39 to 42 show that you don't understand the difference between a single object and an array. You should also be using structures if you know them already. This function is a segmentation fault waiting to happen since you are using illegal array indexes. You shouldn't be trying to print an array of people in this function anyway. You should be printing a single person in this function. The function should not take any arrays as parameters.

I have no clue what this means...

You need to compare the answers with other users and calculate the similarity. After that it will show your best 1Emphasized Text Here0 matches on the monitor.

Edited 4 Years Ago by VernonDozier

I was able to assign an array for each person from the file.

Sorry What I meant was the program should ask 10 questions and put the answers to those questions into an array.Now the File has Data which include answers from other users(which will be in individual arrays). After you answer the 10 questions it should compare your answers with the answers in the file.

Now my next questions is How do I ask the questions and put the answers into a single array.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdlib>
using namespace std;

void outputLine();

int main()
{
    ifstream inClientFile("Answers2.txt");

    if(!inClientFile)
    {
        cerr <<"FIle could not be opened" <<endl;
        exit(1);
    }

    string Howard[10];
    string Zaid[10];
    string Yat[10];
    string Stephanie[10];
    string Adam[10];
    string Ashley[10];
    string Hentrell[10];
    string Corey[10];
    string Topanga[10];
    string Katelyn[10];
    string spaceholder[10];

    for(int i= 0; i <= 9; i++)
    {
    inClientFile >> Howard[i];
    cout << Howard[i] <<" ";


    //outputLine();

    }

    cout<< endl;

    for(int i= 0; i <= 9; i++)
    {
    inClientFile >> Zaid[i];
    cout << Zaid[i]<<" ";
    //outputLine();

    }
    cout<< endl;

    for(int i= 0; i <= 9; i++)
    {
    inClientFile >> Yat[i];
    cout <<Yat[i]<<" ";
    //outputLine();

    }
    cout<< endl;

    for(int i= 0; i <= 9; i++)
    {
    inClientFile >> Stephanie[i];
    cout <<Stephanie[i]<<" ";
    //outputLine();

    }
    cout<< endl;

    for(int i= 0; i <= 9; i++)
    {
    inClientFile >> Adam[i];
    cout <<Adam[i]<<" ";
    //outputLine();

    }

    cout<< endl;
    for(int i= 0; i <= 9; i++)
    {
    inClientFile >> Hentrell[i];
    cout <<Hentrell[i]<<" ";
    //outputLine();

    }
    cout<< endl;
for(int i= 0; i <= 9; i++)
    {
    inClientFile >> Corey[i];
    cout <<Corey[i]<<" ";
    //outputLine();

    }
    cout<< endl;
for(int i= 0; i <= 9; i++)
    {
    inClientFile >> Topanga[i];
    cout <<Topanga[i]<<" ";
    //outputLine();

    }
    cout<< endl;

    for(int i= 0; i <= 9; i++)
    {
    inClientFile >> Katelyn[i];
    cout <<Katelyn[i]<<" ";
    //outputLine();

    }
    cout<< endl;

    for(int i= 0; i <= 9; i++)
    {
    inClientFile >> spaceholder[i];
    cout << spaceholder[i] <<" ";


    //outputLine();

    }

}
This article has been dead for over six months. Start a new discussion instead.