Write a program that stimulates a questionnaire to find a ro


Write a program that stimulates a questionnaire to find a roommate from your CIS 121 Course class. You will ask the user various questions that might determine a suitable match, at least 5 conditions satisfied from the potential questions. Store the names of students who matches your preference in a file called matchfile. Also, store names of students who are not your preferred match in one-dimensional array called NoMatch, size 21.

Solution

#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>

int main()
{
char name[100][100];
FILE *fp;
char nomatch[21][100];
char series[100];
char pet, leader, hp, drinks;
int i, count = 0, match_count[20] = {0}, no_match_count[20] = {0};
int no_of_students = 0;
//open file to store matched names
fp = fopen(\"matchfile1.txt\", \"w\");
printf(\"enter the total nuber of students\\t:\");
scanf(\"%d\",&no_of_students);
for(i=0 ; i<no_of_students; i++)
{
//there are a set of sample questions-modify questions accordingly
printf(\"WELCOME TO THE QUESTIONNAIRE\ \");
printf(\"enter your name\ \");
scanf(\"%s\",&name[i]);
printf(\"1.What is your most favourite TV series?\ \");
scanf(\"%s\",series);
if(strcmp(strlwr(series), \"friends\") == 0)
{
match_count[i] += 1;
}
else
{
no_match_count[i] += 1;
}
printf(\"2.cats or dogs? type \'c\' for cats \'d\' for dogs\ \");
scanf(\" %c\",&pet);
if (tolower(pet) == \'c\')
{
match_count[i] += 1;
}
else
{
no_match_count[i] += 1;
}

printf(\"3. Trump or Obama ? Type \'t\' for Trump and \'o\' for Obama\ \");
scanf(\" %c\",&leader);
if (tolower(leader)== \'o\')
{
match_count[i] += 1;
}
else
{

no_match_count[i] += 1;
}
printf(\"4. harry potter fan? answer with \'Y\' or \'N\'\ \");
scanf(\" %c\",&hp);
if (tolower(hp) == \'y\')
{
match_count[i] += 1;
}
else
{
no_match_count[i] += 1;
}
printf(\"5. Drinks? \'Y\' or \'N\'\ \");
scanf(\" %c\",&drinks);
if (tolower(drinks) == \'y\')
{
match_count[i] += 1;
}
else
{
no_match_count[i] += 1;
}
//if match is found, write the name to the file
if(match_count[i] >= 4)
{
printf(\"match found %s\", name[i]);
fprintf(fp, \"%s\", name[i]);

}
//if match is not found, add the name to nomatch array
else
{
printf(\"%s\", name[i]);
strcpy(nomatch[count++],name[i]);

}

}
fclose(fp);
}

 Write a program that stimulates a questionnaire to find a roommate from your CIS 121 Course class. You will ask the user various questions that might determine
 Write a program that stimulates a questionnaire to find a roommate from your CIS 121 Course class. You will ask the user various questions that might determine

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site