Code: Select all
#include <iostream> //For cout
#include <cstring> //For the string functions
using namespace std;
int main()
{
char food[50];
char name[50];
char lastname[50];
char fullname[100]; // Big enough to hold both name and lastname
int age;
cout<<"Please enter your name: ";
cin.getline ( name, 50 );
cout<<"Enter your last name: ";
cin.getline ( lastname, 50 );
cout<<"please enter your age: ";
cin>> age;
cin.ignore();
cout<<"Enter your favorite food: ";
cin.getline ( food, 50 );
fullname[0] = '\0'; // strcat searches for '\0' to cat after
strcat ( fullname, name ); // Copy name into full name
strcat ( fullname, " " ); // We want to separate the names by a space
strcat ( fullname, lastname ); // Copy lastname onto the end of fullname
cout<<"Your full name is "<< fullname<< ", you are "<< age << ", and your favorite food is "<< food << "." << "\n";
cin.get();
}
now in dev-c++ all you do is go to file - new - project - console app. then you name it at erase everything and put the code in. all you do after that is go to execute - compile. when that finished then you go to execute - run.
now to break it down so you actually know what you did
fom the #include <iostream> to the int main() i wont explain because that would be redundant.
everything after a "//" is irrelevant... it is just notes.
the first sections with the char and int stuff is just were i defined variables the [50] and [100] are how big the input can be.
the stuff that comes after cout<< is computer outouts.
the cin.getline is used for inputing chars (charactar variables) .
the cin>> is for imputting integers, doubles, and strings.
the ( name, 50 ) part of the cin.getline ( name, 50 ); is telling the program to get the first 50 charactars of what was inputted.
the cin.ignor(); tells it to ignor the enter key after you input your age so the program wont terminate.
read the notes on the fullname[0] and strcat things and if you dont get it pm me. I think it is pretty explanitory though.
the cin.get(); at the very end is so that you can read the last output statement and then press any key when you want the program to terminate... without that line the program would close when you press enter after you input the last input in the program.
i saved the most basic part for last... you put a ; after every line in between the curly braces ({}).
i think that covers it all... if you dont get something and need help, then feel free to pm me. i hope this has helped. have a good day!