Strange function problem!!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 2
Reputation: AorA is an unknown quantity at this point 
Solved Threads: 0
AorA AorA is offline Offline
Newbie Poster

Strange function problem!!

 
0
  #1
Oct 15th, 2008
  1. #include <iostream>
  2. #include <windows.h>
  3. using namespace std;
  4.  
  5. void about(){
  6. cout<<"Expence-List 14/10/2008:"<<endl
  7. <<"Brought to you by www.******.com"<<endl
  8. <<"Programmed by **********."<<endl;
  9. Sleep(4000);
  10. system("cls");
  11. }
  12.  
  13.  
  14. int MenuOne(){
  15. int MenuSelection=0;
  16. cout<<"What would you like to do?"<<endl
  17. <<"--------------------------------"<<endl
  18. <<"1. Create a new expence list."<<endl
  19. <<"2. Edit a previous expence list."<<endl
  20. <<"3. View a saved expence list."<<endl
  21. <<"4. Settings"<<endl
  22. <<"5. About."<<endl
  23. <<"6. Close Program"<<endl
  24. <<"--------------------------------"<<endl
  25. <<endl;
  26. cin>>MenuSelection;
  27. system("cls");
  28. return MenuSelection;
  29. }
  30.  
  31.  
  32. int MenuProcessing(int MenuSize,int MenuSelection){
  33. int b=1;
  34. if(MenuSelection>MenuSize){
  35. cerr<<"You've entered an invalid option!"<<endl
  36. <<"Try again!."<<endl;
  37. Sleep(2000);
  38. system("cls");
  39. return 0;
  40. }
  41.  
  42. while(MenuSize>b){
  43. if(MenuSelection=b){
  44. }
  45.  
  46. }
  47.  
  48. b++;
  49. }
  50.  
  51.  
  52. int main(){
  53. start:
  54. int MenuSelection=0,EventStatis;
  55. about();
  56. MenuSelection=MenuOne();
  57. EventStatis=MenuProcessing(6,MenuSelection);
  58. if(EventStatis=0){
  59. goto start;
  60. }
  61. return 0;
  62. }

so thats my code right.
where it says the function menuprocessing. I need a menuprocessing thingo cause i using lots and lots of menus.
so what i want is for where the

  1. while(MenuSize>b){
  2. if(MenuSelection=b){
  3. }
  4.  
  5. }
is i want it to send it to the approbate selected menu thing.
so something like a function array....

  1. void MenuOne[1](){
  2. }

so when
  1. MenuMelection=b
it would go to the
  1. MenuOne[b]();

sucks that function arrays don't exist.

how would i go about doing something like that?
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 671
Reputation: Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough Freaky_Chris is a jewel in the rough 
Solved Threads: 113
Freaky_Chris's Avatar
Freaky_Chris Freaky_Chris is offline Offline
Practically a Master Poster

Re: Strange function problem!!

 
0
  #2
Oct 15th, 2008
use a switch statement, then call the function you are after.

  1. switch(b){
  2. case 1:
  3. menu1();
  4. break;
  5. case 2:
  6. menu2();
  7. break;
  8. case 3:
  9. menu3();
  10. break;
  11. default:
  12. std::cout << "Invalid Choice!";
  13. break;
  14. }

I think that is what you are after,
Chris
Knowledge is power -- But experience is everything
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Strange function problem!!

 
0
  #3
Oct 15th, 2008
Use a while loop instead of goto start.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 305
Reputation: stilllearning has a spectacular aura about stilllearning has a spectacular aura about 
Solved Threads: 43
stilllearning stilllearning is offline Offline
Posting Whiz

Re: Strange function problem!!

 
1
  #4
Oct 16th, 2008
Not to keep harping on this, but you really need to be careful about the difference between an assignment (=) and a comparison (==).

This means that you are assigning the value of the variable b to that of the variable MenuSelection.
[/icode] if(MenuSelection=b){ [/icode]

This means that you are comparing the variables MenuSelection and b
[/icode] if(MenuSelection == b){ [/icode]
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2
Reputation: AorA is an unknown quantity at this point 
Solved Threads: 0
AorA AorA is offline Offline
Newbie Poster

Re: Strange function problem!!

 
0
  #5
Oct 16th, 2008
Lol oops thats bout the ==
Rofl umm forgot that thats a true and false and the other is a assignment was =.
Ty
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC