Oct 3, 2015 at 12:12pm UTC
It doesn't work at all. Do I have to add something to make "y" and "n" available?
Oct 3, 2015 at 1:52pm UTC
With that I finish this, can i add more words for the same task? If I try, somehow, to add more words for case(Y) and case(N) it gets blind. Thanks for everything by the way.
Oct 3, 2015 at 2:11pm UTC
look at your enum enum decision {Y,N};
it contains two elements, Y and N, you could add more or change them too, for instance enum decision{yes,no,ok,tomorrow}
then you have 4 case for your switch (decision) case (yes),case (no),case (ok),case (tomorrow)
Last edited on Oct 3, 2015 at 2:12pm UTC
Oct 3, 2015 at 2:22pm UTC
I mean more words to lead to case(Y), I need for example yes,no,nu,da, it's possible?
Oct 3, 2015 at 2:47pm UTC
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
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
string str;
enum decision {yes,no,nu,da};
decision whichone;
cout << "Wanna hear a joke?" << endl;
getline(cin,str);
if (str =="yes" ){
whichone = yes;
}
else if (str=="no" ){
whichone= no;
}
else if (str =="nu" ){
whichone = nu;
}
else if (str=="da" ){
whichone= da;
}
//what = response;
switch (whichone){
case (yes):
cout<<"I'm yes" <<endl;
break ;
case (nu):
cout<<"I'm no" <<endl;
break ;
case (nu):
cout<<"I'm nu" <<endl;
break ;
case (da):
cout<<"I'm da" <<endl;
break ;
}
return 0;
}
It's possible you just put as many values as you want in the
enum
and with the name string that you want...each "word" will be a case for you....
Last edited on Oct 3, 2015 at 3:08pm UTC
Oct 3, 2015 at 3:13pm UTC
What if I wanna nu = no & da = y task? What command do you use to pause the console when executing program? I dont like the system("Pause").
Oct 3, 2015 at 3:16pm UTC
I have done the code, I still need a pause code, i'm not sure which to use.
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
#include <string>
#include <fstream>
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
string str;
enum decision {Y,N,n,y};
decision whichone;
cout << "Wanna hear a joke?(Y/N)" << endl;
getline (cin,str);
if (str =="Y" );
if (str =="y" )
{
whichone = Y;
}
else if (str =="N" );
else if (str =="n" )
{
whichone= N;
}
switch (whichone){
case (Y):
cout << "UrsAWarLord Anti-Mage EleGiggle" << endl;
break ;
case (N):
cout << "FeelsBadMan, see ya" << endl;
break ;
}
cout << endl;
cout << "Press any key to continue..." ;
getch();
}
Last edited on Oct 3, 2015 at 3:31pm UTC
Oct 3, 2015 at 3:43pm UTC
where do you need a pause?? does it have a time, or you want carry on executing after press a button??
and you can do this....
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
if ((str =="Y" ) or ( str == "y" ));
{
whichone = Y;
}
else if ((str =="N" ) or (str=="n" ));
{
whichone= N;
}
Last edited on Oct 3, 2015 at 3:45pm UTC
Oct 4, 2015 at 7:11am UTC
I need a pause to the ending because when i run the .exe it closes immediately. Secondly, can you tell me how to make a delay at a "spamming" cout?