PDA

View Full Version : Im really new to this but.....



ChrisMUK
07-17-2002, 05:26 PM
Hello

Im really new to this and i want to make a little dos program that will just display a message in a dos window.
But the only problem is when i run it, it shuts the box down really fast before you can even read it.

Here is an example code:

#include <iostream.h>

int main()
{
cout<<"HEY, you, I'm alive! Oh, and Hello World!";

return 0;

}

Any ideas?

I need it so it will just keep the box open then also when they click enter it will shut it down.

Sorry but im new to this only started learning it a few days ago.

Thank you,
Chris

Traveller
07-17-2002, 05:54 PM
Just use cin.get() right before the return 0 statement. This will keep the app open until the user presses any key.

Kelvin
07-18-2002, 06:45 AM
besides, you can type the program name in DOS
for example
Both of the code(abc.cpp) and exe(abc.exe) file are located in C:\MyCode
Then choose run at start menu, type cmd or command
then just type MyCode\abc

or
C:\>cd MyCode
C:\MyCode>abc

The result is visible and no extra code is required.
Please note that it is case-insensitive in DOS

Waldo2k2
07-18-2002, 09:46 AM
you can also:


#include <conio.h>

...
cin>>whatever;
cout<<whatever<<endl;
getch();
return 0;
}

//OR

#include <stdlib.h>

...
cin>>whatever;
cout<<whatever<<endl;
system("PAUSE");
return 0;
}

whichever you want to do, getch waits for a user to press "any key" same with pause

VBprogrammer
07-18-2002, 11:25 AM
lol, or just run it from the command prompt...

Quantrizi
07-18-2002, 04:51 PM
Originally posted by Waldo2k2

whichever you want to do, getch waits for a user to press "any key" same with pause
Actually, getch() doesn't output any messages, while pause outputs "Press any key to continue..."

civix
07-19-2002, 12:35 AM
put a system("PAUSE"); right before the return 0; but make sure you have windows.h included! :D

Quantrizi
07-19-2002, 06:30 AM
u don't need windows.h, just stdlib.h (or cstdlib) for system("PAUSE");

ChrisMUK
07-20-2002, 08:06 AM
Ok got that working...... how can i make it so i can have writing on a new line?

ChrisMUK
07-20-2002, 08:13 AM
Also what i would like this thing to do is display one line first then about 10 seconds after display the second line then another 10 seconds after display another line.

Can this be done?

Kelvin
07-20-2002, 09:47 AM
Originally posted by ChrisMUK
Ok got that working...... how can i make it so i can have writing on a new line?

cout<<"\n"; // a new line
printf("\n"); // also a new line

ChrisMUK
07-20-2002, 10:01 AM
Ok got the line thing working.

Now any idea on the thing where it will display different lines at different times?

Traveller
07-20-2002, 10:06 AM
Try using sleep(timeout); where timeout is an int representing the number of milliseconds you wish to wait.

ChrisMUK
07-20-2002, 10:11 AM
Can you just show me an example of what you mean. As i said im new to this and am only just learning it.

Traveller
07-20-2002, 10:16 AM
Ask and ye shall recieve ;)


#include<iostream>
#include<windows.h>
#include <conio.h>

using namespace std;


int main(void){
cout<<"This is my first line";
Sleep(3000); //wait for three seconds
cout<<endl<<"this is my second line of text";
Sleep(3000);
cout<<endl<<endl<<"This is my final line of text";
cin.get();
return(0);
}

ChrisMUK
07-20-2002, 10:18 AM
I see.... thanks!