Name: Anonymous 2007-06-12 10:52 ID:NALSuzi+
HAI
I'm learning some C++ and last night wrote this:
#include <iostream>
using namespace std;
int main()
{
char gender[30];
char fname[50];
char sname[50];
char hate[30];
char wep[30];
char hobby[50];
cout<<"Please do not use spaces in your answer, it will mess up the program due to bad writing =/ "<<endl;
cout<<endl;
/* Yes I'm rubbish ok? */
cout<<"Please enter either he/she, according to your gender: ";
cin>> gender;
cin.ignore();
cout<<"And what is your first name?: ";
cin>> fname;
cout<<"Well hello there, "<< fname <<"! What is your surname?: ";
cin>> sname;
cin.ignore();
cout<<"Thanks. So far you have told me that you are a "<< gender <<", and your name is "<< fname <<" "<< sname <<"."<<endl;
cout<<endl;
cout<<"What is the one thing you hate most?: ";
cin>> hate;
cin.ignore();
cout<<"What is your weapon of choice?: ";
cin>> wep;
cin.ignore();
cout<<"What is your favourite hobby/pastime?: ";
cin>> hobby;
cin.ignore();
cout<<endl;
cout<<"Ok, let's begin our story..."<<endl;
cout<<endl;
cout<<endl;
cout<<""<< fname <<" "<< sname <<" thought "<< gender <<"'d take a break from "<< hobby <<"."<<endl;
cout<<""<< gender <<" decided to rid the world of all traces of "<< hate <<", once and for all."<<endl;
cout<<"So, brandishing a "<< wep <<", "<< gender <<" set off to seek out and destroy "<< hate <<"..."<<endl;
cout<<"But "<< gender <<" died on the mission and "<< hate <<" remained forever more."<<endl;
cout<<"Poor "<< fname <<", "<< gender <<" should have stuck with "<< hobby <<"."<<endl;
cin.get();
return 0;
}
As you can see, I'm a total n00b with only a basic knowledge of int, float and char. I was wondering which type i could use so that you choose one of 2 options, and most importantly, how I could allow spaces to be used in input without messing up how the program remembers it. Tried google but failed.
I'm learning some C++ and last night wrote this:
#include <iostream>
using namespace std;
int main()
{
char gender[30];
char fname[50];
char sname[50];
char hate[30];
char wep[30];
char hobby[50];
cout<<"Please do not use spaces in your answer, it will mess up the program due to bad writing =/ "<<endl;
cout<<endl;
/* Yes I'm rubbish ok? */
cout<<"Please enter either he/she, according to your gender: ";
cin>> gender;
cin.ignore();
cout<<"And what is your first name?: ";
cin>> fname;
cout<<"Well hello there, "<< fname <<"! What is your surname?: ";
cin>> sname;
cin.ignore();
cout<<"Thanks. So far you have told me that you are a "<< gender <<", and your name is "<< fname <<" "<< sname <<"."<<endl;
cout<<endl;
cout<<"What is the one thing you hate most?: ";
cin>> hate;
cin.ignore();
cout<<"What is your weapon of choice?: ";
cin>> wep;
cin.ignore();
cout<<"What is your favourite hobby/pastime?: ";
cin>> hobby;
cin.ignore();
cout<<endl;
cout<<"Ok, let's begin our story..."<<endl;
cout<<endl;
cout<<endl;
cout<<""<< fname <<" "<< sname <<" thought "<< gender <<"'d take a break from "<< hobby <<"."<<endl;
cout<<""<< gender <<" decided to rid the world of all traces of "<< hate <<", once and for all."<<endl;
cout<<"So, brandishing a "<< wep <<", "<< gender <<" set off to seek out and destroy "<< hate <<"..."<<endl;
cout<<"But "<< gender <<" died on the mission and "<< hate <<" remained forever more."<<endl;
cout<<"Poor "<< fname <<", "<< gender <<" should have stuck with "<< hobby <<"."<<endl;
cin.get();
return 0;
}
As you can see, I'm a total n00b with only a basic knowledge of int, float and char. I was wondering which type i could use so that you choose one of 2 options, and most importantly, how I could allow spaces to be used in input without messing up how the program remembers it. Tried google but failed.