Good Day!!!

I have a problem in creating a code using dev cpp. Can you complete my code? This is my code:

#include <iostream.h>
#include <string.h>
void change();
void clue();
void menu();
void compare();
char n1[8];
char n2[8];
char n;


main(){
      
       do{
            char name[20];
            char n;
            system ("cls");
           
            cout<<"Menu:\n";
            cout<<"1. Clue:\n";
            cout<<"2. Change password?\n";
            cout<<"3. Exit\n";
            cout<<" Enter your choice:\n";
            cin>>n;
           
            system ("cls");
           
           
            switch (n){
                  
                   case '1':
                        char clue1[20];
                           
                            clue();
                           
                           
                            break;
                           
                   case '2':
                        change();
                        break;
                        compare();
                        break;
                       
                   case '3':
                        cout<<"You're done";
                        break;
                       
                       
                        }
                        getchar () ;
                       getchar () ;
                        }
                        while (n!='3') ;
                         getchar () ;
                        getchar () ;
                        return 0 ;
                        }
                       

void clue () {
    
     cout<<"Enter your password first...\nPress enter!!";
     }
    
void change(){
     char ch;
     char password[20];
      char clue[20];
    
          cout<<"You want to enter your password?\n";
          cout<<"Yes or No";
          cin>>ch;
                  if(ch=='y'){
                              cout<<"Enter your password: ";
                              cin>>password;
                              cout<<"Enter your clue: \n";
                              cin>>clue;
                              getchar();
                              system("cls");
                             
                              menu();
                                     if(n==1){
                                    strcpy(password,clue);
                                       system("cls");
                                       }
                                       }    
                  compare();
                                      
                                       }
void menu(){
     cout<<"Menu:\n";
            cout<<"1. Clue:\n";
            cout<<"2. Change password?\n";
            cout<<"3. Exit\n";
            cout<<" Enter your choice:\n";
            cin>>n;
            }
   
          
void compare(){
     int y;
     char clue2[20];
     char password[20];
     char n1[20];
     char n2[20];
    
     cout<<"Enter your old password: ";
     cin>>n1;
     y=(strcmp(password,n1));
     if(y!=0){
              cout<<"Enter new password: ";
              cin>>n2;
              cout<<"Enter new clue: ";
              cin>>clue2;
              cout<<"Congrats!You're done!";
              }
             
              else
              if(y==0){
              system("cls");
              cout<<"Invalid Password!";
              }
              }

Please cooperate with me. I need your response today!!!
Thank you very much. :( :'(

Recommended Answers

All 10 Replies

Sounds like you're in a hurry...
First of all, DON'T USE <iostream.h> and <string.h>...
Instead use <iostream> and <cstring>.
Second, main can't be declared like that, it has to be:

int main(){
//code here
return 0;
}

Cheers!

EDIT: and yes, you are using system(), that means you have to include header for it!
and yes, if using objects from std namespace, you have to declare that you're using it, write
using namepsace std;
at front, although it's a bad habit

I need the exact code. Yes, I'm in a hurry.
Will you help me?

please do me a favor.... can you please edit my code and show me the correct code... please... thank you... for doing me a favor....

>Can you complete my code?
No, why should I? We will help, but we won't do it for you, so unless you have a specific problem, im not doing a thing.

#include <iostream>
#include <string>

using namespace std;

void change(), clue(), menu(), compare();
char n1[8], n2[8], n, password[20];


int main(){
    do{
           char name[20];
           system ("cls");
           
           cout<<"Menu:\n";
           cout<<"1. Clue:\n";
           cout<<"2. Change password?\n";
           cout<<"3. Exit\n";
           cout<<" Enter your choice:\n";
           cin>>n;
           system ("cls");
           
           switch (n){
                  case '1':
                       char clue1[20];
                       clue();
                  break;
                  
                  case '2':
                       change();
                       break;
                       compare();
                  break;
                  
                  case '3':
                       cout<<"You're done";
                  break;
                  }                  
                  cin.get();
                  cin.get();
                  } while (n!='3');
                  
                  cin.get();
                  cin.get();
                  
    return 0 ;
}


void clue () {
     cout<<"Enter your password first...\nPress enter!!";
}

void change(){
     char ch;
     char clue[20];
     
     cout<<"You want to enter your password?\n";
     cout<<"Yes or No";
     cin >> ch;
     
     if(ch=='y'){
                 cout << "Enter your password: ";
                 cin >> password;
                 cout << "Enter your clue: \n";
                 cin >> clue;
                 cin.get();
                 system("cls");
                 
                 menu();
                 
                 if(n==1){
                          strcpy(password,clue);
                          system("cls");
                          }
                 }
                 compare();
}

void menu(){
     cout << "Menu:\n";
     cout << "1. Clue:\n";
     cout << "2. Change password?\n";
     cout << "3. Exit\n";
     cout << " Enter your choice:\n";
     cin >> n;
}


void compare(){
     int y;
     char clue2[20];
     char n1[20];
     char n2[20];
     
     cout << "Enter your old password: ";
     cin >> n1;
     
     y=(strcmp(password,n1));
     
     if(y!=0){
              cout<<"Enter new password: ";
              cin>>n2;
              cout<<"Enter new clue: ";
              cin>>clue2;
              cout<<"Congrats!You're done!";
              }
              
              else if(y==0){
                   system("cls");
                   cout<<"Invalid Password!";
                   }
}

Hope this fixes it...I just corrected some parts, i didn't see if it would get you desirable results, at any rate it compiles.

I just did some minor synatx changes (ONLY SYNTAX). The Rest is for you to figure out

I dont get it . When the person asks for a clue, You tell him to give the password first. And when he trys to type in a password you ask whether you need any clue.

That gets the user nowhere. I recommend that you devise a small flowchart on exactly what your program has to do and then start programming accordingly.

I dont get it . When the person asks for a clue, You tell him to give the password first. And when he trys to type in a password you ask whether you need any clue.

That gets the user nowhere. I recommend that you devise a small flowchart on exactly what your program has to do and then start programming accordingly.

Well the program doesn't do anything exciting... I just checked its syntax, and I see your point, it does nothing. Added Functionality should be coded by 'jrrr'.

Shouldn't the include<string> be actually #include<cstring>?
He doesn't use any string object, only string functions like strcmp, strcpy etc...

Shouldn't the include<string> be actually #include<cstring>?
He doesn't use any string object, only string functions like strcmp, strcpy etc...

Yes, but then again, this is a C++ forum, not C, isn't it? Anyway #include<cstring> contains very basic functions... If he needs to add more functionality to the program then using #include<string> would be best.

I don't get it ....

Why are you overwriting your password with the clue in change() ? strcpy(password,clue); and why are you calling compare() from change even when the user does not enter a password .. coz then you have nothing to compare really ?

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.