C++ help? how to make this wait until key press.?

im writing a basic C++ code and it has no errors, but at the end i wrote std::endl; to make it pause for a key stroke, but it wont, is there an answer to this? Im using visual studio 2005, and writing in its C++, so i think its the same as visual C++ 2005. here is the code: // tutorial.cpp : Defines the entry... show more im writing a basic C++ code and it has no errors, but at the end i wrote std::endl; to make it pause for a key stroke, but it wont, is there an answer to this? Im using visual studio 2005, and writing in its C++, so i think its the same as visual C++ 2005.

here is the code:

// tutorial.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}

// this is a comment
// this program will accept numbers and display their sum

#include <iostream>

void main()
{
//define variables
float num1;
float num2;
float total;

// Enter data for variables

std::cout << "Enter a value for the first variable: ";
std::cin >> num1;
std::cout << "Enter a value for the second variable: ";
std::cin >> num2;

// Add the two numbers together
total = num1 + num2;

// Display the result
std::cout << "The sum of the numbers = " << total << "\n";
std::cin.get(); //wait for keypress
}

it should in theory wait till i press a key, but i entered 5, thenhit enter, entered 5 again, and hit enter and i coul;d barely see a flash of 10 before it closed.
1 answer