C++ declaration of a variable to hold a table of 5 records

Hi all, im doing a program to store name, age, time and fitness. and i need to hold a table of 5 such records.
can i do this?

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
#include <iostream>
using namespace std;
int name1, age1, time1, fitness1;
int name2, age2, time2, fitness2;
int name3, age3, time3, fitness3;
int name4, age4, time4, fitness4;
int name5, age5, time5, fitness5;
int choice;
int main()
{
	while(true)
	{
	cout << "fitness level 1 : More than 48 min," <<endl; 
	cout << "fitness level 2 : More than 44, but less than or equal to 48 min,"<<endl; 
	cout << "fitness level 3 : More than 40, but less than or equal to 44 min,"<<endl; 
	cout << "fitness level 4 : More than 36, but less than or equal to 40 min,"<<endl; 
	cout << "fitness level 5 : Less than 36 min"<<endl;
	cout << "Which Profile would you like to key, 1, 2, 3, 4 and 5?" <<endl;
	cin >> choice;
	if (choice == 6)
			break; //get out of while loop
		else
			{
				switch(choice)
		{
			case 1 :cout << "please enter name" << endl;
			cin >> name1;
			cout << "please enter age" << endl;
			cin >> age1;
			cout << " please enter time" << endl;
			cin >> time1;
			cout << "please enter fitness"<< endl;
			cin >> fitness1;
			cout << "Thanks You" <<endl;
			break; 
			case 2 :cout << "please enter name"<<endl;
			cin >> name2;
			cout << "please enter age"<<endl;
			cin >> age2;
			cout << " please enter time"<<endl;
			cin >> time2;
			cout << "please enter fitness"<<endl;
			cin >> fitness2;
			cout << "Thanks You" <<endl;
			break; 
			case 3 :cout << "please enter name"<<endl;
			cin >> name3;
			cout << "please enter age"<<endl;
			cin >> age3;
			cout << " please enter time"<<endl;
			cin >> time3;
			cout << "please enter fitness"<<endl;
			cin >> fitness3;
			cout << "Thanks You" <<endl;
			break; 
			case 4 :cout << "please enter name"<<endl;
			cin >> name4;
			cout << "please enter age"<<endl;
			cin >> age4;
			cout << " please enter time"<<endl;
			cin >> time4;
			cout << "please enter fitness"<<endl;
			cin >> fitness4;
			cout << "Thanks You" <<endl;
			break; 
			case 5 :cout << "please enter name"<<endl;
			cin >> name5;
			cout << "please enter age"<<endl;
			cin >> age5;
			cout << " please enter time"<<endl;
			cin >> time5;
			cout << "please enter fitness"<<endl;
			cin >> fitness5;
			cout << "Thanks You" <<endl;
			break; 
			default : cout <<"Invalid choice selected, please try again" << endl;
				}
	cin.ignore();
	cin.ignore();
}
	}
}
It's time to start using structs or classes OP: http://www.cplusplus.com/doc/tutorial/structures/
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
#include <iostream>
#include <string>

int main()
{
    const int NRECORDS = 5 ;
    std::string name[NRECORDS] ;
    int age[NRECORDS] = {0} ;
    int time[NRECORDS] = {0} ;
    int fitness[NRECORDS] = {0} ;


    while( true )
        {
            std::cout << "fitness level 1 : More than 48 min,\n";
            std::cout << "fitness level 2 : More than 44, but less than or equal to 48 min,\n";
            std::cout << "fitness level 3 : More than 40, but less than or equal to 44 min,\n";
            std::cout << "fitness level 4 : More than 36, but less than or equal to 40 min,\n";
            std::cout << "fitness level 5 : Less than 36 min\n";
            std::cout << "Which Profile would you like to key, 1, 2, 3, 4 and 5?\n";

            int choice ;
            std::cin >> choice;

            if( choice == 6 ) break; //get out of while loop

            else if( choice >= 0 && choice < 6 )
            {
                std::cout << "please enter name\n";
                std::cin >> name[choice];
                std::cout << "please enter age\n";
                std::cin >> age[choice];
                std::cout << " please enter time\n";
                std::cin >> time[choice];
                std::cout << "please enter fitness\n";
                std::cin >> fitness[choice];
                std::cout << "Thanks You\n";
            }

            else std::cout << "Invalid choice selected, please try again\n";
        }
}
@ JLBorges: Why would you encourage OP to continue writing this way? This is a text book use case for custom objects.
Topic archived. No new replies allowed.