| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		Snootae Grandmaster Cheater
  Reputation: 0
  Joined: 16 Dec 2006 Posts: 969 Location: --->
  | 
		
			
				 Posted: Mon Apr 30, 2007 3:04 am    Post subject: C++ menu help pls | 
				       | 
			 
			
				
  | 
			 
			
				I am trying to make a program with a menu so i can select different optionso perform calculations
 
 
I'm trying to make it so if you enter 1 you go to option one and so on
 _________________
  | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		FullyAwesome I post too much
  Reputation: 0
  Joined: 05 Apr 2007 Posts: 4438 Location: Land Down Under
  | 
		
			
				 Posted: Mon Apr 30, 2007 3:14 am    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				um u tried using the if, else syntax? i'm still learning C++ atm but a basic if loop should do it shouldn't it? for example.... try this script i just made up... i might have screwed up the synatx a lil but just try something like this and rep me if it works xD or if u use the "use namespace std" thingy for cout and cin do it ur way
 
 
 	  | Code: | 	 		  #include <iostream>
 
 
int main() {
 
 
int option;
 
 
std::cout << "Press 1 for "option 1", press 2 for "option 2".
 
std::cin >> option
 
 
 
if (option = 1) {
 
//Do this....
 
}
 
 
if (option = 2) {
 
//Do this...
 
}
 
 
else {
 
//Do instead
 
}
 
 
//W.E else xD
 
 
return 0;
 
 
} | 	  
 
 
hope this helps xD[/code]
 _________________
  | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		Snootae Grandmaster Cheater
  Reputation: 0
  Joined: 16 Dec 2006 Posts: 969 Location: --->
  | 
		
			
				 Posted: Mon Apr 30, 2007 5:44 am    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				thanks for that but when i tried that it seemed to go to the option =1 code first, ill try it again
 _________________
  | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		appalsap Moderator
  Reputation: 0
  Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
  | 
		
			
				 Posted: Mon Apr 30, 2007 5:57 am    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				| of course it did, he used "=" which assigns 1 to option instead of "==" which compares 1 to option
 | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		Robotex Master Cheater
  Reputation: 0
  Joined: 05 Sep 2006 Posts: 378 Location: The pizza country!
  | 
		
			
				 Posted: Mon Apr 30, 2007 6:31 am    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				i would use
 
switch(option)
 
{
 
  case 1:
 
   etc
 
  case 2:
 
   etc
 
  default:
 
   etc
 
}
 
in this case
 _________________
 
 
ASM/C++ Coder
 
Project Speranza lead developer  | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		DeltaFlyer Grandmaster Cheater
  Reputation: 0
  Joined: 22 Jul 2006 Posts: 666
 
  | 
		
			
				 Posted: Mon Apr 30, 2007 12:53 pm    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				 	  | Robotex wrote: | 	 		  i would use
 
switch(option)
 
{
 
  case 1:
 
   etc
 
  case 2:
 
   etc
 
  default:
 
   etc
 
}
 
in this case | 	  
 
Don't forget your breaks.
 _________________
  
 
Wow.... still working at 827... what's INCA thinking?
 
zomg l33t hax at  this place (IE only). Over 150 people have used it, what are YOU waiting for? | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		FullyAwesome I post too much
  Reputation: 0
  Joined: 05 Apr 2007 Posts: 4438 Location: Land Down Under
  | 
		
			
				 Posted: Tue May 01, 2007 2:08 am    Post subject:  | 
				       | 
			 
			
				
  | 
			 
			
				 	  | appalsap wrote: | 	 		  | of course it did, he used "=" which assigns 1 to option instead of "==" which compares 1 to option | 	  
 
 
yah sorry appalsap is right, i meant to put == when i was writing it but i was a lil unsure...but yah = assigns a value or w.e
 _________________
  | 
			 
		  | 
	
	
		| Back to top | 
		 | 
	
	
		  | 
	
	
		 |