bookworm, you had numerous errors in your code. Here is the fixed code (I have no idea how your code compiled):
Code:
#include <iostream>
int add(int x, int y);
int main()
{
int x;
int y;
std::cout<<"I no.:";
std::cin>>x;
std::cout<<"\nII no.:";
std::cin>>y;
std::cout<<"\nSum is:"<<add(x,y)<<std::endl;
std::cin.get();
return 0;
}
int add(int x, int y)
{
return(x+y);
}
In MSVC++, this still does not wait for user input with the cin.get() command. The reason is that >> does NOT remove the carriage return from the input stream, and when you do not pass any parameters to cin.get(), it takes input until a \0 is found, which is still on the input stream. You can test this by calling std::cin.get() twice in a row - the second one 'works', as the first one grabs the \0 off of the stream.
You must call cin.ignore(), as this will remove the stray carriage return from the input buffer, before you call std::cin.get()
(corrected from elad's comment)