1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
using std::cout;
using std::cin;
using std::getline;
using std::tolower;
using std::endl;
using std::string;
using std::transform;
int main (int argc, char * argv[])
{
std::string name;
cout<<"Program says: Hi, what's your name?"<<endl; //q for name
cout<<"User says: ";
std::getline (cin,name); //get name
cout<<"\nProgram says: Hi "<<name<<", are you fine?"<<endl; //how are you?
cout<<"User says: ";
string word;
string ans;
getline(cin,word);
#include <functional> // ptr_fun<>
/*
std::transform( ans.begin(), ans.end(), ans.begin(), std::ptr_fun <int, int> ( std::tolower ) );
*/
std::string Lower_Ans(std::string ans);
{
std::transform( ans.begin(), ans.end(), ans.begin(), std::ptr_fun <int, int> ( std::tolower ) );
return ans;
}
/*if((ans == "yes")||(ans =="Yes")||(ans=="YES")||(ans=="y")||(ans=="Y"))
if((ans == "yes")||(ans=="y"))*/ // <-- the back up which I used before..
if((ans =="yes")||(ans=="y"))
{cout<<"\nProgram says: That's great! I'm fine to :)"<<endl;} //if yes say me 2
else{cout<<"Program says: Don't worry, it'll be allright!"<<endl;} //if no, encourage user
/* after this part the code is untouched, and not using the new function (just using the old one I had, before applying the new function to all)*/
cout<<"\nProgram says: So tell me "<<name<< ", do you like today's weather too?"<<endl; //do you like the weather?
cout<<"User says: ";
getline(cin,ans);
if((ans == "yes")||(ans =="Yes")||(ans=="YES")||(ans=="y")||(ans=="Y"))
{cout<<"\nProgram says: Cool!";} //if yes, say cool :)
cout<<" So what kind of weather do you like?\nCloudy, Sunny, Rainy, Windy, Humid or Dry? "; //what kind of weather?
string weth;
getline (cin,weth);
if((weth == "cloudy")||(weth =="Cloudy")||(weth=="CLOUDY"))
{cout<<"\nPrgoram says: I guess it's okay if it's cloudy sometimes"<<endl;} //if cloudy, say:
else if((weth == "sunny")||(weth=="SUNNY")||(weth=="Sunny"))
{cout<<"\nProgram says: I love it when it's sunny!"<<endl;}//if sunny say:
else if((weth == "windy")||(weth == "Windy")||(weth=="WINDY"))//if windy do:
{
cout<<"\nProgram says: I only like that when it's hot.. You too?"; //say:
getline (cin,ans);
if((ans == "yes")||(ans =="Yes")||(ans=="YES")||(ans=="y")||(ans=="Y"))
{cout<<"\nProgram says: Great! That's something we have in common then!"<<endl;} //if yes say:
else {cout<<"\nProgram says: Ah well, people differ"<<endl;} //if no say:
}
else if((weth=="Humid")||(weth=="humid")||(weth=="HUMID"))
{cout<<"\nProgram says: I realy don't like it when it's humid.."<<endl;}
else if((weth=="dry")||(weth=="DRY")||(weth=="Dry"))
{cout<<"\nProgram says: I guess it's okay when it's dry, as long as it isn't too hot"<<endl;}
system("Pause"); // To do: make a good press enter to continue function!
return 0;
}
|