Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ halp =/

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.

Name: Anonymous 2007-06-12 18:42 ID:zFwWLW41

It is easier to get some C++ code to compile.  The only problem is it won't do what you wanted (likely crash).

B&D type systems like Haskell (and Ada) make it much harder to get the code to compile, but when you do finally manage it, it almost always works.

Which do you prefer?  Grovelling through stack traces, or fixing bizarre (unless you've a PhD. in type theory) type checker errors.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List