stupidest error ever


the whole program works but when i tried to put the last else statement in on line 113 there is a error and i know its the stupidest little syntax error and i want someone to show me how stupid i am for messing it up..
thanks in advance



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <iostream>
#include <string>

using namespace std;

struct PersonRec
{
string firstName, lastName;
int age;

bool operator==(PersonRec& rhs)
{
//Will return true if both names are equal
return ( rhs.firstName == firstName && rhs.lastName == lastName );
}
};
void displayOldest(PersonRec rec[], int size)
{
int indexOfOldest = 0;

for(int i = 0; i < size; ++i)
{
if(rec[i].age > rec[indexOfOldest].age)
indexOfOldest = i;
}

cout << "\nThe oldest person is: \n"
<< "Name: " << rec[indexOfOldest].firstName << " " << rec[indexOfOldest].lastName << endl
<< "Age: " << rec[indexOfOldest].age << endl;
}
void displayYoungest (PersonRec rec[],int size)
	{
int indexOfYoungest = 0;

for(int i = 0; i < size; ++i)
{
if(rec[i].age < rec[indexOfYoungest].age)
indexOfYoungest = i;
}

cout << "\nThe youngest person is: \n"
<< "Name: " << rec[indexOfYoungest].firstName << " " << rec[indexOfYoungest].lastName << endl
<< "Age: " << rec[indexOfYoungest].age << endl;
}
void printRecords(PersonRec rec[], int size)
{
for (int i = 0; i<size; i++)
	{
		cout<<rec[i].firstName<<' '<<rec[i].lastName<<' '<<rec[i].age<<endl;

	}
}

int main()
{
PersonRec* thePeople = NULL;
int size = 0;

while(size < 1)
{
cout << "How many people's information would you like to store: ";
cin >> size;
}

thePeople = new PersonRec[size];

//Get the input
for(int i = 0; i < size; ++i)
{
cout << "Please enter the first name of person #" << i+1 << ": ";
cin >> thePeople[i].firstName;
cout << "Please enter the last name of person #" << i+1 << ": ";
cin >> thePeople[i].lastName;
cout << "Please enter the age of person #" << i+1 << ": ";
cin >> thePeople[i].age;

//Check for equality if we have mroe than 1 entry
if(i > 0)
{
for(int j = 0; j < i; ++j)
{
if(thePeople[i] == thePeople[j])
{
--i;
cout << "\n\nCannot enter same name, please try again...\n\n";
}
}
}
}
char choice;

if (choice = 'A'||'B'||'C')
{	cout<<"Plese Enter Max Number of Records"<<endl;//max number of records
	cout<<"if you would like to see the oldest enter 'A'  "<<endl;//ask if user wants the oldest information
	cout<<"if you would like to see the youngest enter 'B'  "<<endl;
	cout<<"if you would like to see all records of informaion enter 'C'"<<endl;
	
	cout<<"Please enter choice for which\n";
	cout<<"records you would like to see\n";
	cout<<"choice is CAP sensitive"<<endl;
	cin>>choice;
	switch(choice)
	{case 'A': displayOldest(thePeople,size);
		break;
	case 'B':displayYoungest(thePeople,size);
	break;
	
	case 'C':printRecords(thePeople,size);
	
	break;
	}

else 
	cout<<"Please Enter a valid character remember it is CAP sensitive"



cin.sync();
cin.get();
return 0;
}}
Fix your indentation and you'll see the error.
As an aside, this: if (choice = 'A'||'B'||'C') is almost certainly not what you meant.

(choice = 'A'||'B'||'C') sets the value of choice to A, and then comes out as true, always always always. Perhaps you meant:
if (choice == 'A'||choice =='B'||choice =='C')


ok so now i have a bigger problem it wont stop looping now i know its in the if statement somwhere in between 90 and 119
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <iostream>
#include <string>

using namespace std;

struct RecsPerson
{
string firstName, lastName;
int age;

bool operator==(RecsPerson& rhs)
{
//Will return true if both names are equal
return ( rhs.firstName == firstName && rhs.lastName == lastName );
}
};
void displayOldest(RecsPerson rec[], int SIZE)
{
int indexOfOldest = 0;

for(int i = 0; i < SIZE; ++i)
{
if(rec[i].age > rec[indexOfOldest].age)
indexOfOldest = i;
}

cout << "\nThe oldest person is: \n"
<< "Name: " << rec[indexOfOldest].firstName << " " << rec[indexOfOldest].lastName << endl
<< "Age: " << rec[indexOfOldest].age << endl;
}
void displayYoungest (RecsPerson rec[],int SIZE)
	{
int indexOfYoungest = 0;

for(int i = 0; i < SIZE; ++i)
{
if(rec[i].age < rec[indexOfYoungest].age)
indexOfYoungest = i;
}

cout << "\nThe youngest person is: \n"
<< "Name: " << rec[indexOfYoungest].firstName << " " << rec[indexOfYoungest].lastName << endl
<< "Age: " << rec[indexOfYoungest].age << endl;
}
void printRecords(RecsPerson rec[], int SIZE)
{
for (int i = 0; i<SIZE; i++)
	{
		cout<<rec[i].firstName<<' '<<rec[i].lastName<<' '<<rec[i].age<<endl;

	}
}

int main()
{
RecsPerson* People = NULL;
int SIZE = 0;

while(SIZE < 1)
{
cout << "How many people's information would you like to store: ";
cin >> SIZE;
}

People = new RecsPerson[SIZE];

//Get the input
for(int i = 0; i < SIZE; ++i)
{
cout << "Please enter the first name of person #" << i+1 << ": ";
cin >> People[i].firstName;
cout << "Please enter the last name of person #" << i+1 << ": ";
cin >> People[i].lastName;
cout << "Please enter the age of person #" << i+1 << ": ";
cin >> People[i].age;

//Check for equality if we have mroe than 1 entry
if(i > 0)
{
for(int j = 0; j < i; ++j)
{
if(People[i] == People[j])
{
--i;
cout << "\n\nCannot enter same name, please try again...\n\n";
}
}
}
}
char choice;

cout<<"Please enter choice for which\n";
	cout<<"records you would like to see\n";
	cout<<"choice is CAP sensitive"<<endl;

	cin>>choice;
 
	if (choice == 'A'||choice =='B'||choice =='C')
	{
	cout<<"Plese Enter Max Number of Records"<<endl;//max number of records
	cout<<"if you would like to see the oldest enter 'A'  "<<endl;//ask if user wants the oldest information
	cout<<"if you would like to see the youngest enter 'B'  "<<endl;
	cout<<"if you would like to see all records of informaion enter 'C'"<<endl;
	
	
	
	switch(choice)
	{case 'A': displayOldest(People,SIZE);
		break;
	case 'B':displayYoungest(People,SIZE);
	break;
	
	case 'C':printRecords(People,SIZE);
	
	break;
	}}

	else 
	cout<<"Please Enter a valid character remember it is CAP sensitive"<<endl;



cin.sync();
cin.get();
return 0;
}
What do you mean, "it won't stop looping"?

The menu pops up AFTER you enter a choice. (maybe that's why you think it's "looping" -- because you were waiting for the menu to show up, when the program was actually waiting for you to input the menu choice)

Otherwise, it runs fine for me.
Topic archived. No new replies allowed.