GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Dec-2007, 09:49
raziel raziel is offline
New Member
 
Join Date: Nov 2007
Posts: 8
raziel is on a distinguished road

Function access problem


Hello everyone, I need a little help with a program, acctualy with a part of it. I'm trying to make a program that represets the functioning of a cash dispenser using functions so that I can return to the first menu at anytime, but I can't access a function that hasn't been declared up to that point.

I haven't done much with the code because of the problem above, the only compiler error is the following: "implicit declaration of function 'int main()' "
CPP / C++ / C Code:
#include<iostream>
#include<string>

int user_type=00;
int user_pass=00;
int user_option=00;

int usermenu ()
{
 do{if(user_option==00)
       {cout<<"Please select your option: "<<endl;}
    else{cout<<"Please type a valid option: "<<endl;}
    cout<<"1. Withdraw"<<endl<<"2. Change Password"<<endl;
    cin>>user_option;
/*this is the problem*/if (user_option==0) main();} while(user_option!=1 && user_option!=2 && user_option!=0);

 system("pause");
 return 0;
}

void main ()
{
 do{if(user_type==00)
      {cout<<"Welcome to the bank, please type the corresponding option for your user: "<<endl;}
    else{cout<<"Please enter a valid option: "<<endl;}
    cout<<"1. Client"<<endl<<"2. Administrator"<<endl;
    cin>>user_type;} while(user_type!=1 && user_type!=2);
    if(user_type==1)
      {do{if(user_pass==00)
         {cout<<"Please enter your user password: "<<endl;}
       else{cout<<"The password is not valid, please enter it again: "<<endl;}
       cin>>user_pass;} while(user_pass>9999 || user_pass<1000);
      }
    else if(user_type==2){}
    if(user_pass==0) main();
    else usermenu ();
}

As you can see the code is written up to the part where the user has to type one of the options provided, after that the program ends.
I want to make it work so that the user can return to the first menu typing a '0'.
Any ideas on how I could do this preferably using functions would be appreciated.
  #2  
Old 07-Dec-2007, 10:02
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 440
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Function access problem


I'm not sure if you can call main() like that. What I would do if I were you is take all the stuff in main() and put it into a new function called MainMenu(). This way, in main() you can just call MainMenu().
  #3  
Old 07-Dec-2007, 10:26
raziel raziel is offline
New Member
 
Join Date: Nov 2007
Posts: 8
raziel is on a distinguished road

Re: Function access problem


Like this?:

CPP / C++ / C Code:
#include<iostream>
#include<string>

int user_type=00;
int user_pass=00;
int user_option=00;

int usermenu ()
{
 do{if(user_option==00)
       {cout<<"Please select your option: "<<endl;}
    else{cout<<"Please type a valid option: "<<endl;}
    cout<<"1. Withdraw"<<endl<<"2. Change Password"<<endl;
    cin>>user_option;
/*the problem still here!*/if (user_option==0) mainmenu();} while(user_option!=1 && user_option!=2 && user_option!=0);

 system("pause");
 return 0;
}

void mainmenu ()
{
 do{if(user_type==00)
      {cout<<"Welcome to the bank, please type the corresponding option for your user: "<<endl;}
    else{cout<<"Please enter a valid option: "<<endl;}
    cout<<"1. Client"<<endl<<"2. Administrator"<<endl;
    cin>>user_type;} while(user_type!=1 && user_type!=2);
    if(user_type==1)
      {do{if(user_pass==00)
         {cout<<"Please enter your user password: "<<endl;}
       else{cout<<"The password is not valid, please enter it again: "<<endl;}
       cin>>user_pass;} while(user_pass>9999 || user_pass<1000);
      }
    else if(user_type==2){}
    if(user_pass==0) mainmenu();
    else usermenu ();
}

void main ()
{
 mainmenu();
}

Please tell me if I got you wrong.
Thanks
  #4  
Old 07-Dec-2007, 11:24
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 440
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Function access problem


That looks like what I was saying. Also, just out of curiosity, why does usermenu() return an integer?
  #5  
Old 07-Dec-2007, 15:23
raziel raziel is offline
New Member
 
Join Date: Nov 2007
Posts: 8
raziel is on a distinguished road

Re: Function access problem


Good thing I undrstood, but I keep getting almost the very same problem: implicit declaration of function 'int mainmenu ()'
It won't compile as before.

The answer for the second one is because I thought it was needed to exit the function and the program.
 
 

Recent GIDBlog2nd Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help with input files. Efferus CPP / C++ Forum 2 24-Nov-2007 16:19
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 13:12
[Tutorial] Function Pointers aaroncohn CPP / C++ Forum 4 17-Feb-2006 11:33
Revising Script style ?????? pepee MySQL / PHP Forum 4 14-Apr-2004 04:59
Another problem dealing with main() and driver function tommy69 C Programming Language 4 20-Mar-2004 19:46

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 04:31.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.