C++ iomanip layouting [closed]

Layout Before exiting my function
Layout after Re-entering my function
why does my layout doesn’t keep its like resetting whenever i exit the function

this is my whole code i dont know what to do anymore lol
my project is a student management system using array or vector i tried vector but i cant fully understand it so i go for the array

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

int idnumber[10], age[10], students = 0, choice;
float subject1[10], subject2[10], subject3[10], subject4[10], subject5[10], subject6[10], subject7[10];
string name[10], school[10], course[10], bday[10], adress[10];
double average[10];
 

void mainmenu();
void studentmenu();
void editstudentinfo();
void studentinformation();
void displaystudentinformation();
void studentidfinder();
void studentsgrades();
void deleteinfo();
void deanslister();
void status();

void main(){
    mainmenu();
}
void mainmenu(){
    do
    {
        system("cls");
        cout << "STUDENTS INFORMATION MANGEMENT SYSTEM\n";
        cout << "1.Students Information\n";
        cout << "2.Dean Lister's List\n";
        cout << "3. Students Status\n";
        cout << "4. Exit\n";
        cout << "Enter Choice(1-4): ";
        cin >> choice;
        switch (choice){
            case 1:
                system("cls");
                studentmenu();
                break;

            case 2:
                system("cls");
                deanslister();
                    break;
            case 3:
                system("cls");
                status();
                    break;
            case 4:
                exit(0);
                    break;
            default:
                system("cls");
                cout << "Invalid Choice!\n\n";
                system("pause");
                    break;
        }
    
    } while (choice != 4);
    



}
void studentmenu(){
    do{
        system("cls");
        cout << "\t\t\tENTER TRANSACTION TYPE\n";
        cout << "1. Add Students Information\n";
        cout << "2. Display Infromation of Student\n";
        cout << "3. Edit Infromation of Student\n";
        cout << "4. Search Student\n";
        cout << "5. Edit Students Grades\n";
        cout << "6. Delete Students Information\n";
        cout << "7. Back\n";
        cout << "8. Exit\n";
        cout << "Enter Choice(1-8): ";
        cin >> choice;

        switch (choice)
        {
            case 1:
                studentinformation();
                    break;
            case 2:
                displaystudentinformation();
                    break;
            case 3:
                editstudentinfo();
                    break;
            case 4:
                studentidfinder();
                    break;
            case 5:
                studentsgrades();
                    break;
            case 6:
                deleteinfo();
                    break;
            case 7:
                mainmenu();
                    break;
            case 8:
                exit(0);
                break;
        }   
    } while (choice != 8);

}
void editstudentinfo(){\
    system("cls");
    int searcher;
    bool finder = false;
    if (students == 0)
    {
        cout << setw(70) << "No students information inputted" << '\n';
    }
    else
    {
        cout << setw(70) << "EDIT STUDENTS INFORMATION" << setw(50) << '\n' << '\n';    
        cout << "Enter ID Number of Student: ";
        cin >> searcher;

        for(int a = 0; a < students; a++)
        {
            if (searcher == idnumber[a])
            {           
                cout << "Enter Information of Student Number: " << idnumber[a] << '\n';
                cin.ignore();

                cout << "1. Enter Name: ";
                getline(cin, name[a]);

                cout << "2. Enter Age: ";
                cin >> age[a];
                cin.ignore();

                cout << "3. Enter Adress: ";
                getline(cin, adress[a]);
        
                cout << "4.Enter School: ";
                getline(cin, school[a]);

                cout << "5. Enter Course: ";
                getline(cin , course[a]);
                finder = true;
                break;
            }
        }
        if(!finder)
        {
            cout << "ID number " << searcher << " not found!\n\n";
        }
    }
    system("pause");
}
void studentinformation(){
    system("cls");
    bool checker = false;
    int a = 0;
        for (a = 0; a < 1; a++)
        {
            cout << setw(70) << "STUDENTS INFORMATION" << setw(50) << '\n' << '\n';
            cout << "ID number: ";
            cin >> idnumber[students];
            cin.ignore();
            for (int i = 0; i < students; i++)
            {
                do
                {
                    cout << "ID Number Already Inputted\n";
                    cout << "Enter Valid ID Number: ";
                    cin >> idnumber[students];
                    cin.ignore();
                } while (idnumber[students]== idnumber [i]);
            }
            cout << "1. Enter Name: ";
            getline(cin, name[students]);
            

            cout << "2. Enter Age: ";
            cin >> age[students];
            cin.ignore();
            cout << "3. Enter Adress: ";
            getline(cin, adress[students]);
        
            cout << "4.Enter School: ";
            getline(cin, school[students]);

            cout << "5. Enter Course: ";
            getline(cin , course[students]);        
            students++;
            break;
        }
        cout << "All Students Has Been Added\n\n";
        system("pause");
        do
            {
                system("cls");
                cout << "Would You Like to add more students?\n\n";
                cout << "1. Yes\n";
                cout << "2. No\n";
                cin >> choice;
                switch (choice)
                {
                case 1:
                    studentinformation();
                        break;
                case 2:
                    studentmenu();
                        break;

                default:
                    cout << "Invalid Choice!\n\n";
                        break;
                }
            } while (choice != 2);
}
void displaystudentinformation(){
    system("cls");
    if (students == 0)
    {
        cout << setw(65) << "NO STUDENT RECORDS" << setw(50) << '\n' << '\n';
    }
    else
    {
        cout << setw(70) << "STUDENTS INFORMATION" << setw(50) << '\n' << '\n';
        cout << left << setw(24) << "ID Number";
        cout << left << setw(19) << "NAME";
        cout << left << setw(18) << "AGE";
        cout << left << setw(21) << "ADRESS";
        cout << left << setw(21) << "SCHOOL";
        cout << left << setw(21) << "COURSE" << '\n';

        for(int i = 0; i < students; i++)
        {
            cout << setw(24) << idnumber[i];
            cout << setw(19) << name[i];
            cout << setw(18) << age[i];
            cout << setw(21) << adress[i];
            cout << setw(21) << school[i];
            cout << setw(21) << course[i] << '\n';
        }
    }
    system("pause");
}
void studentidfinder(){
    system("cls");
    int searcher;
    bool finder = false;

    if (students == 0)
    {
        cout << "No students information inputted\n\n";
    }

    else
    {
        cout << "Enter Id Number: ";
        cin >> searcher;

        for (int a = 0; a < students; a++)
        {
            if (idnumber[a] ==  searcher)
            {
                cout << setw(65) << "STUDENTS INFORMATION" << setw(50) << '\n' << '\n';
                cout << left << setw(24) << "ID Number";
                cout << left << setw(19) << "NAME";
                cout << left << setw(18) << "AGE";
                cout << left << setw(21) << "ADRESS";
                cout << left << setw(21) << "SCHOOL";
                cout << left << setw(21) << "COURSE" << '\n';

                cout << left << setw(24) << idnumber[a];
                cout << left << setw(19) << name[a];
                cout << left << setw(18) << age[a];
                cout << left << setw(21) << adress[a];
                cout << left << setw(21) << school[a];
                cout << left << setw(21) << course[a] << '\n';
                finder = true;

                if (average[a] == 0)
                {
                    cout << setw(70) << "Grades Not Inputed" << '\n';
                }
                else
                {
                    cout << setw(70) << "STUDENTS GRADES" << setw(50) << '\n' << '\n';
                    cout << left << setw(24) << "ID Number";
                    cout << left << setw(19) << "NAME";
                    cout << left << setw(18) << "AGE";
                    cout << left << setw(21) << "ADRESS";
                    cout << left << setw(21) << "SCHOOL";
                    cout << left << setw(21) << "COURSE" << '\n';

                    for(int i = 0; i < students; i++)
                    {
                        cout << setw(24) << idnumber[i];
                        cout << setw(19) << name[i];
                        cout << setw(18) << age[i];
                        cout << setw(21) << adress[i];
                        cout << setw(21) << school[i];
                        cout << setw(21) << course[i] << '\n';
                    }
                }
            }
        }
        if (!finder)
        {
            cout << "ID Number: " << searcher << " not found.\n\n";
        }
    }
    system("pause");
}
void studentsgrades(){
    system("cls");
    int search;
    bool finder = false;
    if (students == 0)
    {
        cout << "No students information inputted\n\n";
    }
    else
    {
        cout << "Enter Id Number: ";
        cin >> search;
        for (int a = 0; a < students; a++)
        {
            if (search ==  idnumber[a])
            {
                cout << "Information of Student Number: " << idnumber[a];
                cout << "\n\nStudent ID Number : " << idnumber[a] << '\n';
                cout << "Student Name      : " << name[a] << '\n';
                cout << "Age               : " << age[a] << '\n';
                cout << "Address           : " << adress[a] << '\n';
                cout << "Course            : " << course[a] << '\n';
                cout << "School            : " << school[a] << '\n';
                cout << "\n\nEnter Grades of Student Number:  " << idnumber[a] << '\n';

                if (average[a] != 0)
                {
                    cout << "Grades Already Inputted\n";
                    finder = true;
                    break;
                }
                else
                {
                    cout << "1. Computer Programming: ";
                    cin >> subject1[a];

                    if (subject1[a] > 100)
                    {
                        cout << "Error Students Grades is over 100\n\n";
                        subject1[a] = 0;
                    }

                    cout << "2. Introduction To Computing: ";
                    cin >> subject2[a];

                    if (subject2[a] > 100)
                    {
                        cout << "Error Students Grades is over 100\n\n";
                        subject2[a] = 0;
                    }

                    cout << "3. Philippine Popular Culture: ";
                    cin >> subject3[a];

                    if (subject3[a] > 100)
                    {
                        cout << "Error Students Grades is over 100\n\n";
                        subject3[a] = 0;
                    }

                    cout << "4. Math In The Modern World: ";
                    cin >> subject4[a];

                    if (subject4[a] > 100)
                    {
                        cout << "Error Students Grades is over 100\n\n";
                        subject4[a] = 0;
                    }

                    cout << "5. National Service Training Program: ";
                    cin >> subject5[a];

                    if (subject5[a] > 100)
                    {
                        cout << "Error Students Grades is over 100\n\n";
                        subject5[a] = 0;
                    }

                    cout << "6. Understanding The Self: ";
                    cin >> subject6[a];

                    if (subject6[a] > 100)
                    {
                        cout << "Error Students Grades is over 100\n\n";
                        subject6[a] = 0;
                    }

                    cout << "7. Physical Education: ";
                    cin >> subject7[a];
                    
                    if (subject7[a] > 100)
                    {
                        cout << "Error Students Grades is over 100\n\n";
                        subject7[a] = 0;
                    }

                    average[a] = (subject1[a] + subject2[a] + subject3[a] + subject4[a] + subject5[a] + subject6[a] + subject7[a]) / 7;
                    cout << "Average of Student Number: " << idnumber[a] << " is: " << average[a] << '\n' << '\n';
                    finder = true;
                }
            }   
        }
        if (!finder)
        {
            cout << "ID: " << search << " not found!\n\n";
        }
    

    }
    system("pause");
}
void deleteinfo(){
    system("cls");
    int searcher;
    bool finder = false;

    cout << "Enter ID Number of Student to Delete: ";
    cin >> searcher;

    for (int b = 0; b < students; b++)
    {
        if (searcher == idnumber[b])
        {
            
            idnumber[b] = idnumber[b + 1];
            name[b] = name[b + 1];
            age[b] = age[b + 1];
            adress[b] = adress[b + 1];
            school[b] = school[b + 1];
            course[b] = course[b + 1];
            subject1[b] = subject1[b +1];
            subject2[b] = subject2[b + 1];
            subject3[b] = subject3[b + 1];
            subject4[b] = subject4[b + 1];
            subject5[b] = subject5[b + 1];
            subject6[b] = subject6[b + 1];
            subject7[b] = subject7[b + 1];
            average[b] = average[b + 1];
            students--;
            finder = true;
            cout << "Student Number: " << searcher << " deleted\n\n";
        }
    }
    if (!finder)
    {
        cout << "Student Number: " << searcher << " has no records\n\n";
    }
    system("pause");
}
void deanslister(){
    bool finder = false;
    system("cls");
    if (students == 0)
    {
        cout << "No Students Records\n\n";
    }
    else
    {
        for (int i = 0; i < students; i++)
        {
            if (average[i] >= 88)
            {
                average[i] = (subject1[i] + subject2[i] + subject3[i] + subject4[i] + subject5[i] + subject6[i] + subject7[i]) / 7;     
                cout << "List of deans Lister\n\n";
                cout << "ID Number: " << idnumber[i] << '\n';
                cout << "Name: " << name[i] << '\n';
                cout << "\n1. Computer Programming: " << subject1[i] << '\n';
                cout << "2. Introduction To Computing: " << subject2[i] << '\n';
                cout << "3. Philippine Popular Culture: " << subject3[i] << '\n';
                cout << "4. Math In the Modern World: " << subject4[i] << '\n';
                cout << "5. National Service Traning Program: " << subject5[i] << '\n';
                cout << "6. Understanding The Self: " << subject6[i] << '\n';
                cout << "7. Physical Education: " << subject7[i] << '\n';

                cout << "Average of Student Number: " << idnumber[i] << " is: " << average[i] << '\n' << '\n';
                finder = true;
            }
        }
        if(!finder)
        {
            cout << "No Deans Lister Found\n";
        }
    }
    system("pause");
}
void status(){
    system("cls");
    if (students == 0)
    {
        cout << "\n\nNo Students Records\n\n";
    }
    else
    {
        cout << "List of Passing Students\n\n";
        for (int i = 0; i < students; i++)
        {
            if (average[i] >= 75)
            {
                cout << "\nId Number: " << idnumber[i] << '\n';
                cout << "Name: "<< name[i] << '\n';
                cout << "Age: "<< age[i]<< '\n';
                cout << "Adress: "<< adress[i] << '\n';
                cout << "School: "<< school[i] << '\n';
                cout << "Course: "<< course[i] << '\n' << '\n';

                cout << "Grades of Student Number: " << idnumber[i];
                cout << "\n1. Computer Programming: " << subject1[i] << '\n';
                cout << "2. Introduction To Computing: " << subject2[i] << '\n';
                cout << "3. Philippine Popular Culture: " << subject3[i] << '\n';
                cout << "4. Math In the Modern World: " << subject4[i] << '\n';
                cout << "5. National Service Traning Program: " << subject5[i] << '\n';
                cout << "6. Understanding The Self: " << subject6[i] << '\n';
                cout << "7. Physical Education: " << subject7[i] << '\n';
                cout << "Average of Student Number: " << idnumber[i] << " is: " << average[i] << '\n' << '\n';
            }
        }
        cout << "List of Failing Students\n\n";
        for (int i = 0; i < students; i++)
        {
            if (average[i] <= 74)
            {
                    cout << "\nId Number: " << idnumber[i] << '\n';
                    cout << "Name: "<< name[i] << '\n';
                    cout << "Age: "<< age[i]<< '\n';
                    cout << "Adress: "<< adress[i] << '\n';
                    cout << "School: "<< school[i] << '\n';
                    cout << "Course: "<< course[i] << '\n' << '\n';

                    cout << "Grades of Student Number: " << idnumber[i];
                    cout << "\n1. Computer Programming: " << subject1[i] << '\n';
                    cout << "2. Introduction To Computing: " << subject2[i] << '\n';
                    cout << "3. Philippine Popular Culture: " << subject3[i] << '\n';
                    cout << "4. Math In the Modern World: " << subject4[i] << '\n';
                    cout << "5. National Service Traning Program: " << subject5[i] << '\n';
                    cout << "6. Understanding The Self: " << subject6[i] << '\n';
                    cout << "7. Physical Education: " << subject7[i] << '\n';
                    cout << "Average of Student Number: " << idnumber[i] << " is: " << average[i] << '\n' << '\n';
            }
        }
    }
    system("pause");
}

  • 1

    Please take the tour and read How to Ask. Try to create a minimal reproducible example, don’t forget about the minimal. Include everything in the question needed to reproduce the issue, that is: all input, output and expected output. Do not use images for text. Currently the question is unclear. What is “my function” ?

    – 




  • “why does my layout doesn’t keep its like resetting whenever i exit the function” – I suggest that you work on making the actual question clearer.

    – 

  • 1

    fwiw, global variables and using c-arrays rather than std::vector is both commonly mistaken to be simpler by beginners, but they are not and the small effort you need to invest to turn away from them pays off immediately and multiple times. I am almost certain that your current issue is related to having so much global state.

    – 




  • You’ll be glad to hear that you don’t need anyone’s help to figure this out, just a tool you already have: your debugger! This is exactly what a debugger is for: it runs your program, one line at a time, and shows you what’s happening!! This is something that’s every C++ developer must know how to do. With your debugger’s help you’ll able to quickly find all problems in this and all future programs you write, without having to ask anyone for help. Have you tried using your debugger, already? If not, why not? What did your debugger show you?

    – 

Leave a Comment