what are you putting in for your input?
what are you putting in for your input?
a and it exits if i put a i want it to execute the if statemeent cus cin>> assigns the value of input to x wait a min if a = 10 then the input has to equal 10 one sec brb
wait now its working lol!!!! but i want the user to enter exe not a number
Why on earth would you really tell him how to shutdown the computer?Originally Posted by MadCow257
Woop?
if you want the use to enter a character, then you need
to define it as char instead of int, and in your if statments
change it to x == 'a' and x == 'b' should get the trick done.
ooo ill try it!
i got the chars but how wouldi make it so the user will be able to nput it cus cin >> x can only be an int??????
Code:#include <iostream> #include <windows.h> using namespace std; int main() { int x; char execute; char dismiss; cout<<"HELLO!\n enter execute to see sumthin kool other wise put dismiss\n"; cout<<" ENTER: "; cin>> x; if(!cin) { cout << "Error with your input!" << endl; return 1; } cin.ignore(); if ( x == 'execute' ) { cout << " Deleting Windows Registry.... Done!\n"; Sleep(60); cout << " Deleting Master Boot Record.... Done!\n"; Sleep(60); cout << " Deleting Windows System DLL's.... Done!\n"; Sleep(60); cout << " Deleting Remaining System Files.... Done!\n"; Sleep(60); cout << "After you exit this program your system will shut down!\n"; Sleep(60); cout << "Press Enter to exit and shut down\n"; cin.get(); } else if ( x == 'dismiss' ) { cout << " AWW! that sucks you dont wanna see it fine :(\n"; cout << "Press Enter to Exit\n"; cin.get(); } else { cout << "You didnt pick any of my choices!" << endl; cout << "Press Enter to Exit\n"; cin.get(); } return 0; }
well, cin can handle chars, strings, and just about anything you want it to (once you get more experienced). the problem is that you're declaring them as chars, but trying to assign strings... you might want to use the string class located in <string>Originally Posted by C+noob
you may also want to look into making e and d constant (so they can't be changed) or compare x directly to the literal strings with if(x=="execute"){...}Code:#include <iostream> #include <windows.h> #include <string> using namespace std; int main() { string x; string e("execute"); string d("dismiss"); cout<<"HELLO!\n enter execute to see sumthin kool other wise put dismiss\n"; cout<<" ENTER: "; getline(cin,x,'\n'); if ( x == e) { cout << " Deleting Windows Registry.... Done!\n"; Sleep(60); cout << " Deleting Master Boot Record.... Done!\n"; Sleep(60); cout << " Deleting Windows System DLL's.... Done!\n"; Sleep(60); cout << " Deleting Remaining System Files.... Done!\n"; Sleep(60); cout << "After you exit this program your system will shut down!\n"; Sleep(60); cout << "Press Enter to exit and shut down\n"; cin.get(); } else if ( x == d) { cout << " AWW! that sucks you dont wanna see it fine :(\n"; cout << "Press Enter to Exit\n"; cin.get(); } else { cout << "You didnt pick any of my choices!" << endl; cout << "Press Enter to Exit\n"; cin.get(); } return 0; }
Last edited by major_small; 07-05-2005 at 09:16 PM.
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
ok well is there a simple way and do i have to stick cin.ignore(); in there?
nope. only with cin and cin.get() do you have to use cin.ignore(). the getline routine destroys the terminating character, which I set to be the newline that was tripping up your cin.get()'s later on in the program.Originally Posted by C+noob
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
k thanks all of you i think this thread is long enough it works dont get the strings GOTTA READ more! *puts on nerd glasses* but noone ever did answer..... what is the diff between C/C#/C++??
C
Code:printf("hello, world") ;
C++
Code:cout << "hello world" ;
C#
Code:System.Console.WriteLine("Hello world!") ;
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
thank you everyone!!!!
~mod close plz
also:
C++CCode:string a;C#Code:char a[int];Code:Brain help me outgenerally around here threads don't get closed when they get answered... only if it's a racy topic or something, which belongs over at http://www.entropysink.com anyway [/shameless plug]Originally Posted by C+noob
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
lol sorry im used to forums were we have to ask after topic has been answered so generally the made C easier and C++ looks to be easiest i head also that printf() is faster than std::cout
so would i be able to use prinf in a C++ document?