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;
}
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;
}
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