Before I start, I'm sure you've all seen this error, and explained how to solve it many times before, and for that I thank you for bothering to read this, and if you choose to answer, I wish to thank you in advance.
So, the issue I am having is one which I'm sure is simple to solve, and yet I cannot seem to got any viable solution to work. The program compiles fine, and runs perfectly in the compiler console, however, whenever I run the Release executable of my project (which, incidentally is now important, but simply something to help me learn) when I have entered the two integers that the program requires, it calculates the solution, and them immediately closes, giving me no time to see the result. This is the code I am currently using:
#include "stdafx.h"
#include <iostream>
int ReadNumber() // Defining the fuction for lateruse.
{
using namespace std; // Allows us to use cin and cout.
cout << "Please enter an number: " << endl; // Tells the user what to do.
int x; // Defines x so the input can be stored.
cin >> x; // Allows the user to input a number to store in x.
return x;
std::cin.get();
}
void WriteAnswer(int x) // Defining the function for later use.
{
using namespace std; // Lets us use cout.
cout << "The answer is " << x << endl; // The text, and the value x are output.
}
int main()
{
using namespace std;
cout << "This program adds two numbers together." << endl; // Tells the user what the program does.
int x = ReadNumber(); // Gets the value of x from the input.
int y = ReadNumber(); // Gets the value of y fromt he input.
WriteAnswer (x + y); // Uses the funcion to write the result.
return 0;
std::cin.get();
}
I understand that my code is probably messy, and there is much that could be improved on, but your help will be greatly appreciated.
Thank you very much for your time.