C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 28th, 2005, 09:40 PM
Not You Not You is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 10 Not You User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 25 sec
Reputation Power: 0
Please help with this case code

Well, the program seems to be working, except when you try to enter the second part of it.
Code:
//keep in mind i did this is a rather short period of time so there
  // are not a lot of options for the kills part
  // so help me fix this code
  #include <iostream>
  #include <stdio.h>
  #include <conio.h>
  
  using namespace std;
  
  int main()
  {
     int input, h, cs, css, kills;
  
     cout<<"Enter the game you wish to be rated on.\n(1)Halo, (2)Counter-Strike, (3) Counter-Strike: Source, (e)Exit: ";
     cin>> input;
     switch ( input ) {
     case 1:
  	 cout<<"\nEnter you kills for Halo: ";
  	 cin>> kills;
  	 system ("PAUSE");
  		 if ( kills <= 10 && kills >= 1 ) {
  			   cout<<"You suck.\n";
  			   }
  		 else if ( kills <= 15 && kills >= 11 ) {
  			   cout<<"My mom plays better than you. . .\n";
  			   }
  		 else {
  			   cout<<"Lying moron.\n";
  			   }
  	 break;
     case 2:
  	 cout<<"\nEnter your kills for Counter-Strike: ";
  	 cin>> kills;
  	 system ("PAUSE");
  		 if ( kills <= 5 && kills >= 1 ) {
 			 cout<<"I bet everyone on the other team was hacking, right?";
  			  }
  		 else if ( kills <= 10 && kills >= 6 ) {
  			  cout<<"I hope you at least knifed someone.";
  			  }
  		 else {
 			 cout<<"You're either lying out of embarresment, or you are hacking.";
  			  }
  	 break;
     case 3:
  	 cout<<"\nEnter your kills for Counter-Strike: Source: ";
  	 cin>> kills;
  	 system ("PAUSE");
  		 if ( kills <= 5 && kills >= 1 ) {
  			  cout<<"God damn. You nub!";
  			  }
  		 else if ( kills <= 10 && kills >= 6 ) {
  			  cout<<"At least you got some kills. . .";
  			  }
  		 else {
  			  cout<<"You suck, stop lying.";
  			  }
     default:
  	   cout<<"Error\n";
  	 break;
     }
  }
  

Any ideas?

Reply With Quote
  #2  
Old March 1st, 2005, 01:14 AM
af4life af4life is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 4 af4life User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by Not You
Well, the program seems to be working, except when you try to enter the second part of it.
Code:
//keep in mind i did this is a rather short period of time so there
  // are not a lot of options for the kills part
  // so help me fix this code
  #include <iostream>
  #include <stdio.h>
  #include <conio.h>
  
  using namespace std;
  
  int main()
  {
     int input, h, cs, css, kills;
  
     cout<<"Enter the game you wish to be rated on.\n(1)Halo, (2)Counter-Strike, (3) Counter-Strike: Source, (e)Exit: ";
     cin>> input;
     switch ( input ) {
     case 1:
  	 cout<<"\nEnter you kills for Halo: ";
  	 cin>> kills;
  	 system ("PAUSE");
  		 if ( kills <= 10 && kills >= 1 ) {
  			   cout<<"You suck.\n";
  			   }
  		 else if ( kills <= 15 && kills >= 11 ) {
  			   cout<<"My mom plays better than you. . .\n";
  			   }
  		 else {
  			   cout<<"Lying moron.\n";
  			   }
  	 break;
     case 2:
  	 cout<<"\nEnter your kills for Counter-Strike: ";
  	 cin>> kills;
  	 system ("PAUSE");
  		 if ( kills <= 5 && kills >= 1 ) {
 			 cout<<"I bet everyone on the other team was hacking, right?";
  			  }
  		 else if ( kills <= 10 && kills >= 6 ) {
  			  cout<<"I hope you at least knifed someone.";
  			  }
  		 else {
 			 cout<<"You're either lying out of embarresment, or you are hacking.";
  			  }
  	 break;
     case 3:
  	 cout<<"\nEnter your kills for Counter-Strike: Source: ";
  	 cin>> kills;
  	 system ("PAUSE");
  		 if ( kills <= 5 && kills >= 1 ) {
  			  cout<<"God damn. You nub!";
  			  }
  		 else if ( kills <= 10 && kills >= 6 ) {
  			  cout<<"At least you got some kills. . .";
  			  }
  		 else {
  			  cout<<"You suck, stop lying.";
  			  }
     default:
  	   cout<<"Error\n";
  	 break;
     }
  }
  

Any ideas?


There is no break in case 3....

Reply With Quote
  #3  
Old March 1st, 2005, 01:50 PM
Not You Not You is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 10 Not You User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 25 sec
Reputation Power: 0
Quote:
Originally Posted by af4life
There is no break in case 3....

Okay, well I added that, but, it still won't work. After you enter the number for the game, the prompt for the kills comes up. When you type your kills, it just says, "Press any key to continue. . ." It doesn't have the second prompt appear. Is it my compiler, or is the script messed up in some minor way that I can't see?

Reply With Quote
  #4  
Old March 1st, 2005, 03:21 PM
BoolBooB BoolBooB is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 36 BoolBooB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 35 m 42 sec
Reputation Power: 4
I can't see all of your code so I don't know what second prompt you are talking about, but I might know what the problem is: cin does weird things with spaces. For instance, let's say you have two fields you want to prompt the user for: name and phone number. The code might look something like this:
cout << "Please enter name \n";
cin >> name;
cout << "Please enter phone number \n";
cin >> phone number;

If the user does his entry like this:
BoolBoob <enter>
555-5555 <enter>
You're ok.

However, if the user types somehting like this:
Bool Boob <enter>
555-5555 <enter>
You're screwed. Bool will get assigned to name, Boob will get assigned to phone number, and 555-5555 will be assigned to the next thing prompted for.

I don't know if this is your problmen or not, but you can get around this by using cin.getline()

Reply With Quote
  #5  
Old March 1st, 2005, 08:13 PM
Not You Not You is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 10 Not You User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 25 sec
Reputation Power: 0
Okay, sorry. I'm an idiot. I didn't put, "cin.get();," and, "cin.ignore();," at the end and beginning. God. I'm sorry for wasting everyone's time.

Last edited by Not You : March 1st, 2005 at 09:55 PM. Reason: Spelling

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Please help with this case code


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT