943,754 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 525
  • C++ RSS
Oct 15th, 2008
0

Strange function problem!!

Expand Post »
C++ Syntax (Toggle Plain Text)
  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

C++ Syntax (Toggle Plain Text)
  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....

C++ Syntax (Toggle Plain Text)
  1. void MenuOne[1](){
  2. }

so when
C++ Syntax (Toggle Plain Text)
  1. MenuMelection=b
it would go to the
C++ Syntax (Toggle Plain Text)
  1. MenuOne[b]();

sucks that function arrays don't exist.

how would i go about doing something like that?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AorA is offline Offline
2 posts
since Oct 2008
Oct 15th, 2008
0

Re: Strange function problem!!

use a switch statement, then call the function you are after.

C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 325
Solved Threads: 118
Master Poster
Freaky_Chris is offline Offline
702 posts
since Apr 2008
Oct 15th, 2008
0

Re: Strange function problem!!

Use a while loop instead of goto start.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Oct 16th, 2008
1

Re: Strange function problem!!

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]
Reputation Points: 161
Solved Threads: 43
Posting Whiz
stilllearning is offline Offline
309 posts
since Oct 2007
Oct 16th, 2008
0

Re: Strange function problem!!

Lol oops thats bout the ==
Rofl umm forgot that thats a true and false and the other is a assignment was =.
Ty
Reputation Points: 10
Solved Threads: 0
Newbie Poster
AorA is offline Offline
2 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: someone help with simple problem
Next Thread in C++ Forum Timeline: use c++ upload video to youtube





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC