Click to See Complete Forum and Search --> : Execution Issue


konekohime
February 19th, 2008, 12:40 PM
I am new to writing code.

That being said, I run the *.exe and it executes however there is no output

I have the code copied line for line, I've triple checked and had a friend who writes code for a living check. It compiles, no errors found.....

But no output either.

I think I may have had this issue with the compiler before, but don't remember. I am using dev-c++ 4.9.9.2

/* demonstating paraments */

#include <iostream>
using namespace std;

void mul(int x, int y); //mul prototype

int main()
{
mul(10, 20); //calling mul function
mul(5, 10);
mul(23, 72);

return 0;
}

void mul(int x, int y)
{
cout << x * y << " ";
}

laserlight
February 19th, 2008, 12:46 PM
You can either run the program from the command line or add a cin.get(); just before return 0; in main().

Hermit
February 19th, 2008, 01:05 PM
Usually when debugging a console application on Windows I set a breakpoint at the closing brace of main to keep the console open. Additionally, in Visual Studio there is a "Run Without Debugging" option that keeps the console open after the program terminates, which allows you to see the output of destructors called after main returns... Dev-C++ may have something similar.

The problem with cin.get() at the end of main is that it's often done out of naivety and left in release builds. This is bad behavior for console applications in that it makes them more difficult to automate.

MrViggy
February 19th, 2008, 05:18 PM
The problem with cin.get() at the end of main is that it's often done out of naivety and left in release builds. This is bad behavior for console applications in that it makes them more difficult to automate.
Which is why the proper way of testing a console application is to open a console, and run the executable there.

Viggy