Easy Programming

cin.get() in C++:

In this tutorial, I show you how to use cin.get() in C++ instead of system("pause") to end your programs in a very simple way using an older program. I don't get into anything too heavy or too new.

cin.get() is far more efficient and unlike system("pause"), this should work in non-windows environment without a problem. If you have any questions about the program or functions in general, feel free to ask.

I hope you enjoy the video and if you have any requests feel free to let me know.

Click here to go back

//Programmer:	Nazmus
//Program:		cin.get()
//Website:		EasyProgramming.net


#include <iostream>
#include <ctime> 
#include <cstdlib>
using namespace std;

int main()
{
	int max, random_number, i;
	for(i=1;i<=5;i=i+1){
	cout << "Please input max integer: ";
	cin >> max;

	srand(time(0));
	random_number = (rand () % max) + 1;

	cout << random_number << endl;
	}
	
	cin.ignore();
	cin.get();
}