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-11-2011, 09:26 PM #11
Originally posted by TheUberFail View Post
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.


I've had Codeblocks for at least a year now, so seeing that statement you just made, I'm going to use codeblocks for anything C++. But I do good in visual basic, and that's why I'm usually using Visual Studio.
02-11-2011, 09:27 PM #12
Girby2K11
☮ ☯ ☢ ✔ ➝
Originally posted by TheUberFail View Post
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.


i thought that system("PAUSE") was bad to use on a computer?
02-11-2011, 09:34 PM #13
Originally posted by Girby2K11 View Post
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.


Originally posted by TheUberFail View Post
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.


My friend did actually make a program in C++ using codeblocks, and it ran w/ out having to include windows.h, and scripted in it was the system freeze thing... here is the whole code:
    // Coverterbetterwork.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

int main() (
float ctemp, ftemp;
cout << "Input a temperature in Celcius and Press ENTER:";
cin >> ctemp;
ftemp = (ctemp * 1.Cool Man (aka Tustin) + 32;
cout<< end1;
cout<< "The Fahrenheit Temperature is: " << ftemp;
cout<< end1;
cout<< end1;
system ("pause");
}


int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}


---------- Post added at 03:34 PM ---------- Previous post was at 03:29 PM ----------

Originally posted by Girby2K11 View Post
i thought that system("PAUSE") was bad to use on a computer?


All it does is stop your program from terminating after a function is used. It doesn't "pause" your system lol

The following user thanked skitterz for this useful post:

Girby2K11
02-11-2011, 11:23 PM #14
Ritztro
I am a Game Developer
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;
}
}




A good coder handles all possible answers. So you change you yesNo to a string and should change your if statement to this:

    if (yesNO=="y" || yesNO == "Y" || yesNO == "Yes" || yesNO == "YES" )
{
cout << "OMG - your an illegal immigrant... calling the police";
return 0;
}


You can add more like YEs or yEs or yES or yEs or yeS or ye or ya. Anyway you get the point.
02-12-2011, 10:37 AM #15
Originally posted by Dutch View Post
A good coder handles all possible answers. So you change you yesNo to a string and should change your if statement to this:

    if (yesNO=="y" || yesNO == "Y" || yesNO == "Yes" || yesNO == "YES" )
{
cout << "OMG - your an illegal immigrant... calling the police";
return 0;
}


You can add more like YEs or yEs or yES or yEs or yeS or ye or ya. Anyway you get the point.


Also you can use this

    

#include <conio.h>

input = "yes";

if(toupper(input) == "YES" || toupper(input) == "Y")
toupper converts a string to capitals.




---------- Post added at 05:37 AM ---------- Previous post was at 05:35 AM ----------

Originally posted by skitterz View Post
My friend did actually make a program in C++ using codeblocks, and it ran w/ out having to include windows.h, and scripted in it was the system freeze thing... here is the whole code:
    // Coverterbetterwork.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

int main() (
float ctemp, ftemp;
cout << "Input a temperature in Celcius and Press ENTER:";
cin >> ctemp;
ftemp = (ctemp * 1.Cool Man (aka Tustin) + 32;
cout<< end1;
cout<< "The Fahrenheit Temperature is: " << ftemp;
cout<< end1;
cout<< end1;
system ("pause");
}


int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}


---------- Post added at 03:34 PM ---------- Previous post was at 03:29 PM ----------



All it does is stop your program from terminating after a function is used. It doesn't "pause" your system lol


system function is only in the windows.h library, his codeblocks may have included it when including stdafx.h, or even by default it may use it, because code blocks auto uses it at the end, so my bets is this is already embeded.

system("pause") is not bad to use, its only bad to try use it on all systems or try using it in other types of applications, system pause is directly linked to the CMD console and bat scripting "pause".
02-12-2011, 03:13 PM #16
Ritztro
I am a Game Developer
Originally posted by TheUberFail View Post
Also you can use this

    

#include <conio.h>

input = "yes";

if(toupper(input) == "YES" || toupper(input) == "Y")
toupper converts a string to capitals.




---------- Post added at 05:37 AM ---------- Previous post was at 05:35 AM ----------



system function is only in the windows.h library, his codeblocks may have included it when including stdafx.h, or even by default it may use it, because code blocks auto uses it at the end, so my bets is this is already embeded.

system("pause") is not bad to use, its only bad to try use it on all systems or try using it in other types of applications, system pause is directly linked to the CMD console and bat scripting "pause".


actually, try including cstdlib, I think it works in other OS's too.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo