okay so this is my code for a really simple variable test,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
usingnamespace std;
int main()
{
int thisisanumber; //A non-decimal number
char yourname; //A letter or group of letters
cout<<"Enter a number: ";
cin>> thisisanumber;
cin.ignore();
cout<<"This is the number you entered: "<< thisisanumber <<" Wait whats your name again: ";
cin>> yourname;
cin.ignore();
cout<<"Hey guess what: "<< yourname <<" You built this code\n";
cin.get();
}
so anyway, if when i compile it and run the code, it works fine until it comes to the part that says cout<<"Hey guess what: "<< yourname <<" You built this code\n";
over in that line, in the "yourname" variable area, only the first letter of the name i enter is shown. does anyone know how to fix this?
The declaration of yourname is for a single character. If you want to allow for someone's name then you would need to declare char array - take a look at this article for more information: http://www.cplusplus.com/doc/tutorial/ntcs/
Although as EricDu mentioned you might be better off using the C++ standard string as it's much easier to understand and use: http://www.cplusplus.com/reference/string/