#include <iostream>
#include <fstream>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
using namespace std;
struct Survey
{ char name[100];
int age;
char subject;
char answer[2][13];
}taker[10];
struct Health
{ double weight;
double height;
double BMI;
char BMIcat[100];
int marks;
}health[10];
struct Brain
{ char brain;
int right;
int left;
}brain[10];
......
void NameAndAge(Survey taker[], int i)
{
Header(); //Header.
cout << "\t\t" << "Please Enter The Information Below." << endl << endl;
cout << "Enter your name\t: ";
cin.getline(taker[i].name, 100);
cin.ignore(1000,'\n');
cin.clear(); "; age.
cin >> taker[i].age;
system("cls");
}
int main()
{
char response = 'y';
int oneORboth;
ofstream outB, outH;
outB.open("YourResultForBrain.txt");
outH.open("YourResultForHealth.txt");
int bil;
cout << "Enter how many people are going to take the test? ";
cin >> bil;
system("cls");
while(response != 'n') //Using while loop !n (for repeating survey).
{
Header();
cout << "\t\t\t" << " Hello And Welcome!" << endl;
cout << endl;
cout << "\t\t\t" << " Press Enter To Start" ;
getch();
for (int i=0;i<bil;i++)
{ NameAndAge(taker, i);
cin>>oneORboth;
system("cls");
if(oneORboth == 1)
{
Header(); //Header.
cout << "\t\t\t" << "There Are Two Categorized Surveys." << endl << endl; //Information aboutB survey.
cout << "\t\t" << " Categories: 1. Health 2. Left-Right Brain" << endl << endl;
cout << "\nEnter a category: ";
cin >> taker[i].subject;
switch(taker[i].subject)
{
case '1':
WeightAndHeight(health,i);
HQ(taker, health,i);
break;
case '2':
BQ(taker, brain,i);
break;
}
}
if(oneORboth == 2) //If taker wants to do both surveys.
{
HeaderHealth();
cout << "\t\t\t" << " First Survey; Health";
cout << endl << endl;
cout << "\t\t\t" << " Press Enter To Start" ;
getch();
WeightAndHeight(health,i);
HQ(taker, health,i);
HeaderBrain();
cout << "\t\t\t" << " Second Survey; Brain";
cout << endl << endl;
cout << "\t\t\t" << " Press Enter To Start" ;
getch();
BQ(taker, brain,i);;
}
float m;
m = health[i].height / 100;
health[i].BMI = health[i].weight/(m*m);
if(health[i].BMI < 18.5)
strcpy(health[i].BMIcat,"Underweight");
if((health[i].BMI >= 18.50) && (health[i].BMI<= 24.99))
strcpy(health[i].BMIcat, "Normal");
if((health[i].BMI >= 25.00) && (health[i].BMI <= 29.99))
strcpy(health[i].BMIcat, "Overweight");
if(health[i].BMI >= 30.00)
strcpy(health[i].BMIcat, "Obese");
if(taker[i].subject == '1')
{
outH<< "Name\t\t: " << taker[i].name << endl;
outH << "Age\t\t: " << taker[i].age<< endl;
outH << setiosflags (ios::fixed);
outH << setiosflags (ios::showpoint);
outH << setprecision(2);
outH << "Weight\t\t: " << health[i].weight << endl;
outH << "Height\t\t: " << health[i].height << endl;
outH << "BMI\t\t: " << health[i].BMI << endl;
outH << "BMI Category: " << health[i].BMIcat << endl;
outH << "Correct Answer: "<<health[i].marks << endl;
}
if(taker[i].subject == '2')
{
outB << "Name: " << taker[i].name << endl;
outB << "Age : " << taker[i].age << endl;
if(brain[i].right > brain[i].left)
{
outB << endl;
outB << "You are Right-Brained!" << endl;
outB << barline << endl;
outB << "The Right Brain:" << endl;
outB << barline << endl;
outB << "Unique Traits: " << endl;
outB << "Recognizes faces easily" << endl;
outB << "Expressive" << endl;
outB << "Musical" << endl;
outB << "Reads emotions easily" << endl;
outB << "Colorful" << endl;
outB << "Imaginative" << endl;
outB << "Intuitiove" << endl;
outB << "Creative" << endl;
}
if(brain[i].left > brain[i].right)
{
outB << endl;
outB << "You are Left-Brained!" << endl;
outB << barline << endl;
outB << "The Left Brain " << endl;
outB << barline << endl;
outB << "Unique Traits: " << endl;
outB << "Language learner" << endl;
outB << "Logical" << endl;
outB << "Critical thinker" << endl;
outB << "Great with numbers" << endl;
//Closes brain output.
}
}
if(oneORboth == 2) /* TATA */
{
outH << "Name\t\t: " << taker[i].name << endl;
outH << "Age\t\t: " << taker[i].age << endl;
outH << setiosflags (ios::fixed);
outH << setiosflags (ios::showpoint);
outH << setprecision(2);
outH << "Weight\t\t: " << health[i].weight<< endl;
outH << "Height\t\t: " << health[i].height<< endl;
outH << "BMI\t\t: " << health[i].BMI<< endl;
outH << "BMI Category: " << health[i].BMIcat << endl;
outH<< "Correct Answer: "<<health[i].marks << endl;
}
if(oneORboth == 2)
{
outB << "Name: " << taker[i].name << endl;
outB << "Age : " << taker[i].age << endl;
if(brain[i].right > brain[i].left)
{
outB << endl;
outB << "You are Right-Brained!" << endl;
outB << barline << endl;
outB << "The Right Brain:" << endl;
outB << barline << endl;
outB << "Unique Traits: " << endl;
outB << "Recognizes faces easily" << endl;
outB << "Expressive" << endl;
outB << "Musical" << endl;
outB << "Reads emotions easily" << endl;
outB << "Colorful" << endl;
outB << "Imaginative" << endl;
outB << "Intuitiove" << endl;
outB << "Creative" << endl;
}
if(brain[i].left > brain[i].right)
{
outB << endl;
outB << "You are Left-Brained!" << endl;
outB << barline << endl;
outB << "The Left Brain " << endl;
outB << barline << endl;
outB << "Unique Traits: " << endl;
outB << "Language learner" << endl;
outB << "Logical" << endl;
outB << "Critical thinker" << endl;
outB << "Great with numbers" << endl;
}
}
}
cout << barline << headline << barline;
cout << endl << endl;
cout << "\t\t\t\t Retake?" << endl << endl;
cout << barline << barline << barline << endl << endl;
cout << "y for Yes, n for No." << endl;
cout << "Take survey again?" << endl;
cin >> response;
system("cls");
if(response == 'n')
Credit();
outH.close();
outB.close();
return 0;
}
}
Попытка исправить код в течение нескольких часов, и прогресс не сделан.Все работает отлично, за исключением той части, где печатается имя получателя в блокноте (считайте это квитанцией).Я подозреваю, что у этой части есть какая-то проблема, но я не могу определить, что это.
void NameAndAge(Survey taker[], int i)
{
Header();
cout << "\t\t" << "Please Enter The Information Below." << endl << endl;
cout << "Enter your name\t: ";
cin.getline(taker[i].name, 100);
cin.ignore(1000,'\n');
cin.clear();
cout << "\nEnter your age\t: ";
cin >> taker[i].age;
system("cls");
}
Я публикую только некоторые части кода, потому что оригинальная слишком длинная.