We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,445 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Problems with adding a record

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..

3
Contributors
2
Replies
2 Hours
Discussion Span
1 Year Ago
Last Updated
3
Views
animeocarl
Newbie Poster
1 post since Mar 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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)?

Labdabeta
Practically a Master Poster
621 posts since Feb 2011
Reputation Points: 27
Solved Threads: 31
Skill Endorsements: 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.

Ancient Dragon
Achieved Level 70
Team Colleague
32,275 posts since Aug 2005
Reputation Points: 5,852
Solved Threads: 2,591
Skill Endorsements: 70

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0893 seconds using 2.82MB