Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
#include <iostream>
#include <fstream>
#include <string>

/* */
using namespace std;

string line;
struct course{
	string course_id,course_name,course_type,course_duration,course_mid;
	
};


void add_course()
{
course x;
cout<<"course_id=";
cin>>x.course_id;
cout<<"course_name=";
cin>>x.course_name;
cout<<"course_type=";
cin>>x.course_type;
cout<<"course duration=";
cin>>x.course_duration;

ofstream xfile("cdetails.txt",ios::app);
xfile<<x.course_id<<"\t\t"<<x.course_name<<"\t\t"<<x.course_type<<"\t\t"<<x.course_duration<<"\t\t"<<"\n";
cout<<"course details added successfully"<<"\n";
xfile.close();


	
}










int main(int argc, char** argv) {
	
	
     	
	
	 int option,a;
	 char b,c;
	
	 
	 do{
	 system("cls");
	 cout<<"\t*********************************"<<"\n";
	 cout<<"\t\tMASTER MIND INSTITUE"<<"\n";
	 cout<<"\t*********************************"<<"\n";
	 cout<<"1.user login"<<"\n";
	 cout<<"2.view company details"<<"\n";
	 cout<<"3.Exit"<<"\n";
	 cout<<"enter option number(1-3) = "<<"\n";
     cin>>option;
     
     
     
     if(option==1){
     	
	system("cls");
		string uid,pw,in;
	cout<<"*******************"<<"\n";
	cout<<"  Log-in details"<<"\n";
	cout<<"*******************"<<"\n";
	cout<<"Enter user id  = ";
	cin>>uid; 
	cout<<"Enter password = ";
	cin>>pw;
	
	bool validity= 0;
	//fetch details from the text files
	ifstream file2("llog.txt");
	while(getline(file2,in))  {
		
		//compare the user id
		if(in==uid){
			getline(file2,in);{
			if(in==pw){
				//if user id is matching ,compare the password
				validity = 1;
				break;
			    }
			}
		}
		
		
	}
	file2.close();
	
	
    if (validity==1){
    	cout<<"\n"<<"Login successfull...!!"<<"\n\n";
    	
    	do{
    	
    		cout<<"\n"<<"*******************************"<<"\n";
    		cout<<"\t MASTERMIND INSTITUTE"<<"\n";
    		cout<<"*******************************"<<"\n";
			 	
			 	cout<<"4.View available Training Programs"<<"\n";
                cout<<"5.Manage Course details"<<"\n";
				cout<<"6.Manage Student registration details"<<"\n";
				cout<<"7.Exit"<<"\n";
				cout<<"enter option number(4-7) = ";	
				cin>>a;		 	
    		
    		
    		if (a == 4) {
    			
    			system("cls");
                cout << "\n****** Available Training Programs ******\n\n";
                ifstream ifile("trainingcourse.txt");
                if (!ifile) {
                cout << "Unable to open the file.\n";
                return 1;
                        }

                cout << ifile.rdbuf();
                ifile.close();
                    }
                    
                    else
                    if(a==5){
                    	
                    	do{
                    	 cout<<"\na.add course details"<<"\n";				 	    
				 	     cout<<"b.Search course details"<<"\n";
				 	     cout<<"c.view added course details"<<"\n";
				 	     cout<<"d.exit"<<"\n";
				 	     cout<<"enter option(a-e) : ";
				 	     cin>>b;	
                    		
                      if (b=='a')	{
                      	system("cls");
                      	cout<<"****************************"<<"\n";
                      	cout<<"Add course details"<<"\n";
                      	cout<<"****************************"<<"\n";
                      	add_course();
                      	
                      	
                      	
					  }	
					  else 
					  if(b=='b'){
					  	
					  	
					  }
					  
					  else
					  if(b=='c'){
					  	
					  	
					  	
					  	
					  }
					  else
					  if(b=='d'){
					  	
					  }
					 
                    		
                    		
                    		
						}
                    	
                     while(b != 'a' && b != 'b' && b != 'c' && b != 'd');	
                    	
                    	
					}
					else
			    if(a==6)
			         {
			  	
			  	do{
			  	 system("cls");	
			  	cout<<"\nw.add student details"<<"\n";
			  	cout<<"x.Search student details"<<"\n";
			  	cout<<"y.view added student details"<<"\n";
			  	cout<<"z.exit"<<"\n";
			  	cout<<"enter option(v-z)"<<"\n";
			  	cin>>c;
			  	
			  	if(c=='w'){
			  		
				  }
				  else
				  if(c=='x'){
				  	
				  }
			  	else
			  	if(c=='y'){
			  		
				  }
			  	else
			  	if(c=='z'){
			  		
				  }
	
		}
    	
    	while(c!='w'||c!='x'||c!='y'||c!='z');
        
    	}
		else if(a==7){
			
		}
		 
	    }
	    
	    while (a != 7);
	    
	}
	
	
	else{
	
		cout<<"\n"<<"Login failed........!!"<<"\n\n";
        }
    }
        
		else if(option==2){
			system("cls");
			cout<<"\n******company details******"<<"\n\n";
			ifstream file("cpnydetails.txt");
            if (!file) {
            	//If it fails to open, we print an error message and return a non-zero value to indicate an error
            cout << "Unable to open the file." <<"\n";
            return 1;
                       }

       
       cout << file.rdbuf();//read and display the contents of the file directly on the console

        file.close();
			
		
		}
		else if(option==3){
			system("cls");
			
			cout<<"\nSuccessfully excited the system, thank you!!......";
			exit(0);
		}
		else{
			cout<<"error input!!! enter again\n";
		}
			
      
   }
   while(option != 2);
   
	return 0;
}


What I have tried:

this is a system design and when I logged in using password and username it shows log in successful but the thing is if I entered a wrong password it doesn't show log in failed like I wanted to I've tried chatgpt and fixing this it keeps going to the main 3 options when entered a incorrect password or username please if someone know let me know how to fix this, this program doesn't show errors the only thing is i can not display log in failed
Posted
Updated 29-May-23 1:41am
v4
Comments
Richard MacCutchan 29-May-23 6:32am    
cnt and pls are not proper words.
Please use actual words and not childish txtspk to formulate questions.

You also need to explain exactly what the problem is, and where it occurs, in the code you have posted above.
Member 16016861 29-May-23 6:44am    
i'm sorry i'm running out of time, i will fix that
Richard MacCutchan 29-May-23 7:17am    
It is because after printing the failed message you go back to the beginning and immediately clear the screen, by calling:
system("cls");

so you never see the message. You need to add some code after showing the message which asks the user for some further information.
Member 16016861 29-May-23 8:44am    
thank you so much u saved my life

1 solution

To add to what Richard has said, that coe needs a lot of other improvements.
Start by sorting out the indentation - that makes it a lot easier to read, and that means much better reliability and easier maintenance.

Then break it up into separate functions: Each option calls a function (with an appropriate name) to do that job, instead of having the code in one monolithic function. Again, that improves readbility and maintenance.
C++
int main(int argc, char** argv) {
    int option;
    do {
        showMenu();
        option = getUserSelection();
        switch(option) {
            case optLogin: doLogin(); break;
            case ...
            }
        } while (option != optExit);
    }
Now you have a manageable chunk of code that is easy to work with and understand - and it's a lot harder to muck up existing code when adding or changing an option. And the added bonus is that it's simpler to match up your curly brackets!

main now is simple to read - you can understand what it is doing in a glance and all the detail for each option is separated from the others.
Give it a try!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900