what are you putting in for your input?
Printable View
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?Quote:
Originally Posted by MadCow257
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>Quote:
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;
}
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.Quote:
Originally Posted by C+noob
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!") ;
thank you everyone!!!!
~mod close plz
also:
C++CCode:string a;
C#Code:char a[int];
Code:Brain help me out
generally 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]Quote:
Originally Posted by C+noob
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?