| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
|
#2
|
|||
|
|||
|
Quote:
There is no break in case 3.... |
|
#3
|
|||
|
|||
|
Quote:
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? |
|
#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() |
|
#5
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Please help with this case code |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|