how to define a variable for name

Dear Sir,
I am a beginner doing ist excercise How to define a data type which will represent a name. I have to write a programme forreading a name of user and number of unit consumed and charges. I have used char for name but it returns only one character. What to do?
regards
arora sk


#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int units;
float charges;
char name;
cout<<"enter name of the user\n";
cin >>name;
cout<<"enter units consumed greaer than 300\n";
cin >>units;
charges=100*.4+200*.5+(units-300)*.6;
cout<<"Name of the user is\t";
cout<<name;
cout<<"\nUsage charges are\t";
cout<< charges;
}
#include <string> and use std::string as the type.
I have tried by modifying it as follows but it returns error. Will you please correct it for me
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{ clrscr();
int units;
float charges;
string name;
cout<<"enter name of the user\n";
cin >>name;
cout<<"enter units consumed greaer than 300\n";
cin >>units;
charges=100*.4+200*.5+(units-300)*.6;
cout<<"Name of the user is\t";
cout<<name;
cout<<"\nUsage charges are\t";
cout<< charges;
}


regards,
Arora
You should post the errors you get but I suppose they are because you are using old style headers, remove '.h' from 'iostream' and 'string'. Notice that the new headers use the std namespace

the error messages arre
Compiling SP112E20.CPP:
Error SP112E20.CPP 8: Undefined symbol 'string'
Error SP112E20.CPP 8: Statement missing ;
Error SP112E20.CPP 10: Undefined symbol 'name'
i am using turbo ver 3 which does not uses std and uses .h
regards
arora sk
Wow. Those error messages suck.

Looks like you're wrong, because the compiler is accepting your included header but complaining about string, so I guess you should use std.

PS: Get yourself a real compiler.
Topic archived. No new replies allowed.