-
Need some help
I made this code that you type in your name and it replies back. I type in my name and it works, then I have to type in my last name and when I do and hit enter it closes. Can anyone fix this? Here is the code. This is a DOS program. Thanks!
Code:
#include <iostream.h>
#include <string.h>
int main()
{
char name[50];
char lastname[50];
cout<<"Enter your Name: ";
cin.getline(name, 50, '\n');
if(!strcmpi("Joey", name))
{
cout<<"Ha thats my name also."<<endl;
}
else
{
cout<<"Nope sorry thats not my name.";
}
cout<<"This is your name in uppercase..."<<endl;
strupr(name);
cout<<name<<endl;
cout<<"And this is your name in lower case..."<<endl;
strlwr(name);
cout<<name<<endl;
cout<<"Your name is "<<strlen(name)<<" letters long"<<endl;
cout<<"Enter your lastname:";
cin.getline(lastname, 50, '\n');
strcat(name, " ");
strcat(name, lastname);
cout<<"Your full name is "<<name;
return 0;
}
-
I havn't coded in DOS very much, but I beleive that its
so your program would look like
Code:
//---------------------------------------------------------------------------
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char name[50];
char lastname[50];
cout<<"Enter your Name: ";
cin.getline(name, 50, '\n');
if(!strcmpi("Joey", name))
{
cout<<"Ha thats my name also."<<endl;
}
else
{
cout<<"Nope sorry thats not my name.";
}
cout<<"This is your name in uppercase..."<<endl;
strupr(name);
cout<<name<<endl;
cout<<"And this is your name in lower case..."<<endl;
strlwr(name);
cout<<name<<endl;
cout<<"Your name is "<<strlen(name)<<" letters long"<<endl;
cout<<"Enter your lastname:";
cin.getline(lastname, 50, '\n');
strcat(name, " ");
strcat(name, lastname);
cout<<"Your full name is "<<name << endl;
system("PAUSE");
return 0;
}
the endl; is so that the next line of text is on a new line, and the pause, well, pauses until you hit the "anykey"!
Cheers
Dw
-
Never mind it works! Thanks!
-
That worked? Good to hear
Cheers
DW
-
Code:
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
You should note that these are deprecated. If you have a new enough compiler you should use iostream and cstdlib:
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
//...