Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: muert0 on July 03, 2004, 09:14 PM

Title: Does this work?
Post by: muert0 on July 03, 2004, 09:14 PM
I have this:
   #include <iostream.h>
int          
main()
{
 int thisisanumber;
 cout<<"Please enter a number:";
 cin>>thisisanumber;
 cout<<"You entered: "<<thisisanumber;
 return 0;
}

When I run it I get a  line that says Please enter a number:
I enter a number and the prompt closes.
I tryed doing this and got an error:
     #include <iostream.h>
     #include <stdlib.h>
int
main()
{
 int thisisanumber;
 cout<<"Please enter a number:";
 cin>>thisisanumber;
 cout<<"You entered: "<<thisisanumber;
 system("PAUSE");
 return 0;
}

Is this way off?
Title: Re:Does this work?
Post by: Moonshine on July 04, 2004, 01:42 AM
Quote from: muert0 on July 03, 2004, 09:14 PM
I have this:
   #include <iostream.h>
int          
main()
{
 int thisisanumber;
 cout<<"Please enter a number:";
 cin>>thisisanumber;
 cout<<"You entered: "<<thisisanumber;
 return 0;
}

When I run it I get a  line that says Please enter a number:
I enter a number and the prompt closes.
I tryed doing this and got an error:
     #include <iostream.h>
     #include <stdlib.h>
int
main()
{
 int thisisanumber;
 cout<<"Please enter a number:";
 cin>>thisisanumber;
 cout<<"You entered: "<<thisisanumber;
 system("PAUSE");
 return 0;
}

Is this way off?

It doesn't look like you're using normal quotes ("")...
Title: Re:Does this work?
Post by: muert0 on July 04, 2004, 02:35 AM
Cool it took me a minute to figure out what you were saying. Thanks for the help.
Title: Re:Does this work?
Post by: Adron on July 04, 2004, 03:54 AM
Actually, the prompt closing after entering the number is normal. Having a pause there is useful when debugging, but generally, you don't want a pause when a console application finishes. Try running it from a cmd console, and you'll see.
Title: Re:Does this work?
Post by: muert0 on July 04, 2004, 10:11 AM
Ok I had to go dig around in console mode for a while and remeber how to navigate around in it. Heh, I kept typing ls instead of dir. Oh well what's the command to run the program? I went to the directory the file was in and typed run project 2.exe. And it said run wasn't a valid command.
Title: Re:Does this work?
Post by: Adron on July 04, 2004, 11:35 AM
Just type the name of your exe file. If it's named with a space in it, you have to surround the command with quotes. The exe extension is optional.

c:\projects\project 2\release>"project 2"

Title: Re:Does this work?
Post by: muert0 on July 04, 2004, 11:57 AM
Ok that does make a lot more sense. thanks for the help.
Title: Re:Does this work?
Post by: UserLoser. on July 05, 2004, 02:45 AM
QuoteDoes this work?

You said there's an error, so no.
Title: Re:Does this work?
Post by: Banana fanna fo fanna on July 05, 2004, 08:40 AM
http://unxutils.sf.net