- 1
What's wrong with this code??
what I am trying to achieve is that the program salute you. #include <iostream> using namespace std; int main() { int name; int last; cout<<"Write your first and lastname"<<endl; cin>>name>>last; cout<<"its a pleassure Mr"<<endl; cout<<name<<last<<endl; return 0; } WHAT'S WRONG WITH IT???
7 Answers
+ 3
You are inputting name use a string(array of characters).
#include <iostream>
using namespace std;
int main()
{
char name[20],last[20];
cout<<"Write your first and lastname"<<endl;
cin>>name>>last;
cout<<"its a pleassure Mr"<<endl;
cout<<name<<last<<endl;
return 0;
}
+ 3
int means integer. int can only store numbers from -32767 to 32768.
char stores one alphabet or any other characters even tab spaces,new lines etc.
If we write
char a;
then it can store one character only.
char name[20];
this means I declared a variable that is named 'name' and can store up to 19 characters. That is I allocated it memory equal to 20 bytes.
+ 1
use array of char for holding character values , they wont store in int u need string
0
int?
0
use char*name or string name datatype.
string data type works on latest compiler only
- 1
actually the problem comes once I feed my info
it does not act the way its suppose to be.
instead of greeting it outputs
"it's a pleasure Mr. 01"
- 1
so if I'm right what Mr.Megatron means is that integer does not work for things more complex than numbers right? in order to input more characters we use "char"? I also see that you wrote [20] that means that the length of the input can be no longer than 20 characters right?
what does "char" means??
Thank you folks.