// The function displayMessage is repeadedly called from a loop.
#include <iostream>
usingnamespace std;
//************************************************************
//Definition of functional displayMessage *
//This function displays a greeting *
//************************************************************
void displayMessage()
{
cout << "Hello from the function displayMessage.\n";
}
//*************************************************************
// Function main *
//*************************************************************
int main()
{
cout << "Hello from main.\n";
for ( int count = 0; count < 5; count++ )
displayMessage(); //Call displayMessage
cout << "Back in function main again.\n";
system ("PAUSE");
return EXIT_SUCCESS;
}
I am suppose to get an output of:
Hello from main.
Hello from the function displayMessage.
Hello from the function displayMessage.
Hello from the function displayMessage.
Hello from the function displayMessage.
Hello from the function displayMessage.
Back to function main again.
I believe the problem to be in my for loop but I don't spot it. In stead I get
Hello from main.
Hello from the function displayMessage.
Back in function main again.
Press any key to continue . . .
can anyone check me over because I just don't see it.
This won't even compile, as you have an apostrophe instead of a semicolon at the end of line 25.
Fixing that, the program will give the expected output.
I was able to compile and run your program, with no problems. I changed system ("PAUSED"); to system ("PAUSE"); as I received an error, but it still compiled. ( There is NO system command, "PAUSED" ) If your using Microsoft Visual C++, then you may need to add #include "stdafx.h" . If you're not using that one, which compiler are you using? Knowing that, someone may know better why your program isn't working, while another one, does.
Hello from main.
Hello from the function displayMessage.
Hello from the function displayMessage.
Hello from the function displayMessage.
Hello from the function displayMessage.
Hello from the function displayMessage.
Back to function main again.