View unanswered posts | View active topics It is currently Fri Dec 27, 2024 8:31 am



Reply to topic  [ 38 posts ]  Go to page Previous  1, 2, 3
 C++ 
Author Message
User avatar

Joined: Sat Oct 14, 2006 8:51 pm
Posts: 155
Location: Chair
Reply with quote
Post Re: C++
Kelas wrote:
That quickly turned into a runaway program and threw my computer into the matrix.


#include <iostream>
using namespace std;

int main()
{
cout<<"Yes or no? (1||0)\n";
int choice;
cin>>choice;
switch(choice){
case 1:
cout<<"Hello"<<endl;
system("pause");
break;
case 0:
cout<<"Bye"<<endl;
system("pause");
break;
default:
cout<<"PICK 1 OR 0 ladylike";
main();
}
return 0;
}




This should work.
ChJees forgot to break, lest it continue unabated.


Tue Oct 02, 2007 11:52 pm
Profile
User avatar

Joined: Thu Jul 19, 2007 11:31 am
Posts: 249
Location: Sweden, Hallstavik
Reply with quote
Post Re: C++
Silly me XD! (Maybe because i have not coded in a while :P)


Wed Oct 03, 2007 2:43 am
Profile WWW
User avatar

Joined: Fri Dec 15, 2006 5:28 am
Posts: 978
Location: Texas
Reply with quote
Post Re: C++
I'll test that later, I believe that if I #include<string> and use strings instead of ints, it might work.

Will post results later.


Wed Oct 03, 2007 3:12 am
Profile
User avatar

Joined: Sat Oct 14, 2006 8:51 pm
Posts: 155
Location: Chair
Reply with quote
Post Re: C++
Kelas wrote:
I'll test that later, I believe that if I #include<string> and use strings instead of ints, it might work.

Will post results later.


That's going to be overkill.
If the value is a yes or a no then you should use "bool".

That code above does compile and run the required effect.


Wed Oct 03, 2007 11:42 pm
Profile

Joined: Fri Aug 31, 2007 8:44 am
Posts: 8
Reply with quote
Post Re: C++
Let me fix that 1 for you
Code:
#include <iostream>

using namespace std;

int main()
{
    cout<<"Yes or no?\n";
    string choice;
    cin>>choice;
    if (choice=="yes"){<<"Hello";}
    else if (choice=="no") {cout<<"Bye";}
    else {std::cout<<"PICK YES OR NO ladylike";}
    cin.sync();
    cin.get();
    return 0;
}


Tue Oct 30, 2007 7:42 am
Profile
User avatar

Joined: Fri Apr 27, 2007 7:47 pm
Posts: 88
Reply with quote
Post Re: C++
My bother does C++, and hes good at it. Maybe I can tell him to take a look at it. Something looks wrong to me.. :P


Tue Nov 06, 2007 12:21 am
Profile
User avatar

Joined: Fri Dec 15, 2006 5:28 am
Posts: 978
Location: Texas
Reply with quote
Post Re: C++
We're way past that. I'll commision him to do my next project though.


Tue Nov 06, 2007 12:31 am
Profile
User avatar

Joined: Fri Apr 27, 2007 7:47 pm
Posts: 88
Reply with quote
Post Re: C++
Kelas wrote:
We're way past that. I'll commision him to do my next project though.


Oh, lol sorry. :D


Tue Nov 06, 2007 1:02 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 38 posts ]  Go to page Previous  1, 2, 3

Who is online

Users browsing this forum: Google [Bot]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.165s | 14 Queries | GZIP : Off ]