can you help me with these a little problem of mine..
we are having a pair project where the program is all about enrollment system.
in this program, we need to add a record, view, and search records.
now. my problem is...
i cannot add another record within this code...

#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <conio.h>
#include <windows.h>
using namespace std;

struct TOSAVERECORDS{
    string firstname[true], lastname[true], middleinitial[true], gender[true], address[true];
    int age[true];
} RECORD;  

int main ()
{
    int selection;
    string searchrecord;
    int tempforarray=0;
    string hold;
    start:
    string temp1, temp2, temp3, temp4, temp5;
    int temp6;
    char saverecord, ask;
    system ("CLS");
    cout << "\t\t\t         Welcome to\n";
    cout << "\t\t\t         XYZ School\n";
    cout << "\t\t    Di Makita-kita St., Hanap-hanapin City\n";
    cout << "================================================================================";
    cout << "\t\t\t    1 ---- Add Record\n";
    cout << "\t\t\t    2 ---- View Records\n";
    cout << "\t\t\t    3 ---- Search Records\n";
    cout << "\t\t\t    4 ---- Exit Program\n";
    choice:
    cout << "================================================================================";
//    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 11);
    cout << "\t\t\t    Enter Choice: ";
    cin >> selection;
    
    switch (selection){
           case 1:                                             // ADD RECORD
                system ("CLS");
                cout << "\t\t\t         ADD RECORD\n";
                cout << "================================================================================";
                cout << "Enter Firstname: \t\t";
                cin >> temp1;
                temp1[0] = toupper(temp1[0]);
                cout << "Enter Lastname: \t\t";
                cin >> temp2;
                for (int y=0; y<=temp2.length(); y++){
                      temp2[y] = toupper(temp2[y]);}
                cout << "Enter Middile Initial: \t\t";
                cin >> temp3;
                temp3[0] = toupper(temp3[0]);
                cout << "Enter Gender: \t\t\t";
                cin >> temp4;
                temp4[0] = toupper(temp4[0]);
                cout << "Enter Address: \t\t\t";
                cin >> temp5;
                temp5[0] = toupper(temp5[0]);
                cout << "Enter Age: \t\t\t";
                cin >> temp6;
                cout << "================================================================================";
                cout << "Do you want to save this data?[Y/N]: ";
                cin >> saverecord;
                if (saverecord == 'Y' || saverecord == 'y'){
                   RECORD.firstname[tempforarray] = temp1;
                   RECORD.lastname[tempforarray] =temp2;
                   RECORD.middleinitial[tempforarray] = temp3;
                   RECORD.gender[tempforarray] = temp4;
                   RECORD.address[tempforarray] = temp5;
                   RECORD.age[tempforarray] = temp6;
                   cout << "================================================================================";
                   cout << "\nRECORD SUCCESSFULLY SAVED!\n\n";
                   cout << "================================================================================";
                   tempforarray++;
                   goto start;
                }
                if (saverecord == 'N' || saverecord == 'n'){
                   goto start;
                }
                break;
           case 2:                                          //VIEW RECORD
                system ("CLS");
                cout << "\t\t\t         VIEW RECORDS\n";
                cout << "================================================================================";
                for (int j=0; j<RECORD.lastname[tempforarray].length(); j++){
                    cout << "Name:\t\t" << RECORD.lastname[j] << ", " << RECORD.firstname[j] << " " << RECORD.middleinitial[j] << "." << endl;
                    cout << "Gender:\t\t" << RECORD.gender[j] << endl;
                    cout << "Address:\t" << RECORD.address[j] << endl;
                    cout << "Age:\t\t" << RECORD.age[j] << endl;
                    cout << "================================================================================";
                }
                getch();
                cout << "Return to main menu? [Y/N]: ";
                cin >> saverecord;
                if (saverecord == 'Y' || saverecord == 'y'){
                   cout << "Returning to main menu.\n";
                   system ("PAUSE");
                   goto start;}
                if (saverecord == 'N' || saverecord == 'n'){
                   cout << "Program will exit...";
                   getch();
                   exit(1);}
                break;
           case 3:                                          // SEARCH RECORD
                system ("CLS");
                cout << "\t\t\t         ADD RECORD\n";
                cout << "================================================================================";
                search:
                cout << "Enter Firstname: ";
                cin >> searchrecord;
                cout << "================================================================================";
                searchrecord[0] = toupper(searchrecord[0]);
                for (int h=1; h<=searchrecord.length(); h++){
                    searchrecord[h] = tolower(searchrecord[h]);
                }
                for (int i=0; i<RECORD.lastname[tempforarray].length(); i++){     
                    if (RECORD.firstname[i] == searchrecord){
                       cout << "Search Results Based From The Inputted Records:\n\n";
                       cout << "Name:\t\t" << RECORD.lastname[i] << ", " << RECORD.firstname[i] << " " << RECORD.middleinitial[i] << "." << endl;
                       cout << "Gender:\t\t" << RECORD.gender[i] << endl;
                       cout << "Address:\t" << RECORD.address[i] << endl;
                       cout << "Age:\t\t" << RECORD.age[i] << endl;
                    }
                }
                cout << "\nEND OF RECORDS\n"; 
                cout << "================================================================================";
                cout << "Would you like to search another record? [Y/N]: ";
                question:
                cin >> saverecord;
                if (saverecord == 'Y' || saverecord == 'y'){
                   cout << "================================================================================";
                   goto search;
                }
                if (saverecord == 'N' || saverecord == 'n'){
                   goto start;
                }
                if (saverecord !='Y' || saverecord !='y' || saverecord !='N' || saverecord != 'n') {
                     cout << "================================================================================";
                     cout << "Input Invalid. Please try again.";
                     cout << "================================================================================";
                     goto question;
                }
                                                  
           case 4:                                            // EXIT PROGRAM
                system ("CLS");
                cout << "THANK YOU FOR USING THE SYSTEM! :D\n";
                system ("PAUSE");
                exit(1);
                break;
           default:
                   cout << "================================================================================";
                   cout << "Input Unknown. Please try again.\n";
                   goto choice;
                   break;
    }                                    
    system ("PAUSE");
    return 0;
}

i've been working for this for a couple of days already and still i cannot find what's wrong with these.
can you please help me..

Recommended Answers

All 2 Replies

I haven't read all your code... but why in your record structure do you declare a bunch of string arrays of size true (1)?

Yes, that is odd using true to indicate the number of elements in an array. true is used for boolean operations, such as true or false, and you can't count on true being equal to 1, it could be -1 in some implementations.

Another point -- get rid of all those goto statements because they are considered very bad programming style.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.