0
#include <iostream>
using namespace std;

int main()
{
	int length;
	length = 7;

	cout << "The length is " << length;
	return 0;
}

When i run the program, it outputs everything but the screen comes on real fast and then closes and i cant get it to stay running

4
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by siddhant3s
0

2 options for this problem:

1. Add

cin.get();

just before your return. This waits for user input before exiting the program.

2. Run the program manually from a terminal. Then you can see the output even if the program exits

~J

0

>I prefer option 2.
Same here.
But everyone should use option 2 if you are designing a converter, or a filter. It helps other program to use your program's output as their input.

0
#include <iostream>
using namespace std;

int main()
{
	double f;
	double m;

	cout << "Enter the length in feet ";
	cin >> f;

	m = f / 3.28;

	cout << f << " feet equals " << m << " meters";

	cin.get();

	return 0;
}

Im having the same problem again. I have no problem entering in f, but the out put does the exact same thing. it says the cout statement but it disappears really fast. even when im using cin.get()

0

You did not flushed the stream.
Read http://www.daniweb.com/forums/thread90228.html
Use cin.ignore(); to do this:

#include <iostream>
using namespace std;

int main()
{
    double f;
    double m;
    cout << "Enter the length in feet ";
    cin >> f;
    m = f / 3.28;
    cout << f << " feet equals " << m << " meters";
    cin.ignore();
    cin.get();
    return 0;
}

Also, always post your code in the code tags:
[code=cplusplus] //your code goes here

[/code]

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.