Author |
Message |
Yon
Joined: Sat Oct 14, 2006 8:51 pm Posts: 155 Location: Chair
|
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 |
|
|
ChJees
Joined: Thu Jul 19, 2007 11:31 am Posts: 249 Location: Sweden, Hallstavik
|
Re: C++
Silly me XD! (Maybe because i have not coded in a while )
|
Wed Oct 03, 2007 2:43 am |
|
|
Kelas
Joined: Fri Dec 15, 2006 5:28 am Posts: 978 Location: Texas
|
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 |
|
|
Yon
Joined: Sat Oct 14, 2006 8:51 pm Posts: 155 Location: Chair
|
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 |
|
|
hyperion
Joined: Fri Aug 31, 2007 8:44 am Posts: 8
|
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 |
|
|
cgp114
Joined: Fri Apr 27, 2007 7:47 pm Posts: 88
|
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..
|
Tue Nov 06, 2007 12:21 am |
|
|
Kelas
Joined: Fri Dec 15, 2006 5:28 am Posts: 978 Location: Texas
|
Re: C++
We're way past that. I'll commision him to do my next project though.
|
Tue Nov 06, 2007 12:31 am |
|
|
cgp114
Joined: Fri Apr 27, 2007 7:47 pm Posts: 88
|
Re: C++
Kelas wrote: We're way past that. I'll commision him to do my next project though. Oh, lol sorry.
|
Tue Nov 06, 2007 1:02 am |
|
|
|