Post: [C++] Simple Yes - No Program Funny
02-10-2011, 11:16 PM #1
Girby2K11
☮ ☯ ☢ ✔ ➝
(adsbygoogle = window.adsbygoogle || []).push({}); So at the moment i am a bit ill and learning c++ while ill is a hard thing to do, so i went back a bit and felt like making a program that asks the user 'are you an illegal immigrant' if the user inputs no - yes it says something Smile

im not being racist, if you find it quite offensive just ask me to change the code to your liking. but it has to be a yes - no question for the user.
and so on.

heres the code:

    #include <iostream>
#include <cstdlib>
#include <cmath>

using namespace std;

// simple program using y - n char's yesNO - could be what you want though.

int main()
{

char yesNO;

cout << "Are you an illegal immigrant? y - n: ";

cin >> yesNO;

if (yesNO=='y'Winky Winky
{
cout << "OMG - your an illegal immigrant... calling the police";
return 0;
}

if (yesNO=='n'Winky Winky
{
cout << "Good Your a Fine Civilian Smile";
return 0;
}
if (yesNO < 'n', 'y'Winky Winky
{
cout << "Closing...";
return 0;
}
}

02-10-2011, 11:19 PM #2
Alt
Banned
Nice to see when someone is ill they do something good, ie learn to code Awesome face
02-10-2011, 11:37 PM #3
Originally posted by Girby2K11 View Post
So at the moment i am a bit ill and learning c++ while ill is a hard thing to do, so i went back a bit and felt like making a program that asks the user 'are you an illegal immigrant' if the user inputs no - yes it says something Smile

im not being racist, if you find it quite offensive just ask me to change the code to your liking. but it has to be a yes - no question for the user.
and so on.

heres the code:

    #include <iostream>
#include <cstdlib>
#include <cmath>

using namespace std;

// simple program using y - n char's yesNO - could be what you want though.

int main()
{

char yesNO;

cout << "Are you an illegal immigrant? y - n: ";

cin >> yesNO;

if (yesNO=='y'Winky Winky
{
cout << "OMG - your an illegal immigrant... calling the police";
return 0;
}

if (yesNO=='n'Winky Winky
{
cout << "Good Your a Fine Civilian Smile";
return 0;
}
if (yesNO < 'n', 'y'Winky Winky
{
cout << "Closing...";
return 0;
}
}




On NGU, you can use
     [ /PHP ] to add color to your code.

[php]
#include <iostream>
//cstdlib not used here
//cmath not used here

using namespace std;

// simple program using y - n char's yesNO - could be what you want though.

int main()
{

char yesNO; //beter name would be "userInput" as this decribes what it stores

cout << "Are you an illegal immigrant? y - n: ";

cin >> yesNO;

if (yesNO=='y'Winky Winky
{
cout << "OMG - your an illegal immigrant... calling the police";
}

else if (yesNO=='n'Winky Winky //else if means, "ok if its not y, is it?" this enables us to do
{
cout << "Good Your a Fine Civilian Smile";
}
else //ethis enables us to do else, meaning, ok its not y, and its no n, so do this
{
cout << "Closing...";
}

system("PAUSE"); // a way of pausing the application instead of it ending instantly.

return 0; //return 0 can be moved to end of code, as theres no need repeating it in definite outcomes.
}
02-11-2011, 04:10 AM #4
Originally posted by Girby2K11 View Post
OP IS HUGE


You forgot to add
    system("pause");
right before all of the
    return 0;
statements. Otherwise the program will immediately shut down after clicking enter.
02-11-2011, 09:36 AM #5
Originally posted by skitterz View Post
You forgot to add
    system("pause");
right before all of the
    return 0;
statements. Otherwise the program will immediately shut down after clicking enter.


Ive already fixed it in the above comment :P
02-11-2011, 01:18 PM #6
Originally posted by TheUberFail View Post
Ive already fixed it in the above comment :P


Oh, lol. You should fix the thread since I just went ahead and used the code from the thread:p
02-11-2011, 05:34 PM #7
Girby2K11
☮ ☯ ☢ ✔ ➝
Originally posted by x3 View Post
Nice to see when someone is ill they do something good, ie learn to code Awesome face


good on ya Smile

---------- Post added at 12:32 PM ---------- Previous post was at 12:30 PM ----------

Originally posted by TheUberFail View Post
On NGU, you can use
     [ /PHP ] to add color to your code.

[php]
#include <iostream>
//cstdlib not used here
//cmath not used here

using namespace std;

// simple program using y - n char's yesNO - could be what you want though.

int main()
{

char yesNO; //beter name would be "userInput" as this decribes what it stores

cout << "Are you an illegal immigrant? y - n: ";

cin >> yesNO;

if (yesNO=='y'Winky Winky
{
cout << "OMG - your an illegal immigrant... calling the police";
}

else if (yesNO=='n'Winky Winky //else if means, "ok if its not y, is it?" this enables us to do
{
cout << "Good Your a Fine Civilian Smile";
}
else //ethis enables us to do else, meaning, ok its not y, and its no n, so do this
{
cout << "Closing...";
}

system("PAUSE"); // a way of pausing the application instead of it ending instantly.

return 0; //return 0 can be moved to end of code, as theres no need repeating it in definite outcomes.
}


i put else in and it kept doing things i didnt want it to do so i used if, but thanks for the correction.

---------- Post added at 12:34 PM ---------- Previous post was at 12:32 PM ----------

Originally posted by skitterz View Post
You forgot to add
    system("pause");
right before all of the
    return 0;
statements. Otherwise the program will immediately shut down after clicking enter.


what compiler do you use? i use code::blocks and i think it doesnt allow system("PAUSE"); because people found it wasnt needed also i anted it to end straight away thats why i got rid of cin.get(); Smile
02-11-2011, 08:57 PM #8
Originally posted by Girby2K11 View Post
good on ya Smile

---------- Post added at 12:32 PM ---------- Previous post was at 12:30 PM ----------



i put else in and it kept doing things i didnt want it to do so i used if, but thanks for the correction.

---------- Post added at 12:34 PM ---------- Previous post was at 12:32 PM ----------



what compiler do you use? i use code::blocks and i think it doesnt allow system("PAUSE"); because people found it wasnt needed also i anted it to end straight away thats why i got rid of cin.get(); Smile


I use the Visual Studio Console app compiler. You're code worked fine in visual studio & w/e. But as soon as I hit y, and enter; it closed out immediately. And that's due to not having system pause before the return 0; statements.
02-11-2011, 09:18 PM #9
Originally posted by Girby2K11 View Post
good on ya Smile

---------- Post added at 12:32 PM ---------- Previous post was at 12:30 PM ----------



i put else in and it kept doing things i didnt want it to do so i used if, but thanks for the correction.

---------- Post added at 12:34 PM ---------- Previous post was at 12:32 PM ----------



what compiler do you use? i use code::blocks and i think it doesnt allow system("PAUSE"); because people found it wasnt needed also i anted it to end straight away thats why i got rid of cin.get(); Smile


Originally posted by skitterz View Post
I use the Visual Studio Console app compiler. You're code worked fine in visual studio & w/e. But as soon as I hit y, and enter; it closed out immediately. And that's due to not having system pause before the return 0; statements.



system function is from windows library, you have to include windows.h to use it, also visual studio is a very heavy weight compiler, and uses up allot of CP Resources, you should at least try DevCpp or code::blocks.

The following user thanked TheUberFail for this useful post:

skitterz
02-11-2011, 09:25 PM #10
Girby2K11
☮ ☯ ☢ ✔ ➝
Originally posted by skitterz View Post
I use the Visual Studio Console app compiler. You're code worked fine in visual studio & w/e. But as soon as I hit y, and enter; it closed out immediately. And that's due to not having system pause before the return 0; statements.


yeah, it because the code works perfectly on code::blocks you dont really need the cin.get(); or system("PAUSE") return 0; ends it straight away all you need to press a key.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo