Solved Clearing the user input

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

tvojama

uz42&4fd
Meme Tier VIP
Dank Tier Donator
Apr 1, 2015
377
2,498
10
Hello fellow hackers!
Yet again I need your help:
C++:
#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
	int x;
	int y;
	
	int xmx;
	xmx = 32700;
	int ymx;
	ymx = -32700;
	
	
		cout << "Pick a number you want to multiply." << endl;
		cin >> x;// 

	if (x > xmx) 																			/////
	cout << "Sorry, that number is too high, plese pick another one!" << endl;				/////
	cin.clear();																			/////
	cin >> x;//	<---																			///// 
																							///// UTVRDUJE BROJ X
	if (x < ymx)																			/////
	cout << "Sorry, that number is too high, plese pick another one!" << endl;				/////
	cin.clear();																			/////
	cin >> x;//		<-----																		/////
	
	
		cout << "Chose one more number." << endl;											///// X USPOSTAVLJEN
		cin >> y;//																		///// UNOSI VRIJEDNOST Y

	if (y < ymx)																			/////
	cout << "Sorry that number is too low, please pick another one!" << endl;				/////
	cin.clear();																			/////
	cin >> y;//	<---																			/////
																							///// UTVRDUJE BROJ Y
	if (y > xmx)																			/////
	cout << "Sorry, that number is too high, plese pick another one!" << endl;				/////
	cin.clear();																			/////
	cin >> y;//	<---																			/////


		cout << "You chose :" << x; 
		cout << " and " << y << endl;
		cout << "The end resut is: " << x*y << endl; 

		
	while (!GetAsyncKeyState(VK_F1) & 0x1); //Zatvara se pritiskom F1
		
		return 0;
}
Please ignore the comments, that is how I mark things for myself.
I need help clearing user input marked with <--.
When i run the program it allows you to enter 3 numbers for X (I know why), and 3 for Y.
I think I didn't explain well but I'm pulling an all-nighter so forgive me for that, tell me which part you didn't understand and I will try to explain better.
Code: https://prntscr.com/9e7ym8
 
Last edited:

TBA

Newbie
Full Member
Oct 1, 2012
23
307
1
All you had to do was enter in { } after your if statements
Also the bad thing about this is if you enter a number higher or lower then 32700 or -32700 two it will accept it because it doesnt loop to check if its higher or lower again.

C++:
#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
	int x;
	int y;
	int xmx;
	xmx = 32700;
	int ymx;
	ymx = -32700;

	cout << "Pick a number you want to multiply." << endl;
	cin >> x;

	if (x > xmx)
	{
		cout << "Sorry, that number is too high, please pick another one!" << endl;
		cin.clear();
		cin >> x;				
	}
	 if (x < ymx)
	{
		cout << "Sorry, that number is too low, please pick another one!" << endl;
		cin.clear();
		cin >> x;												
	}
	cout << "Chose one more number." << endl;		
	cin >> y;														
	if (y < ymx)
	{
		cout << "Sorry, that number is too low, please pick another one!" << endl;
		cin.clear();
		cin >> y;																	
	}
	 if (y > xmx)
	{
		cout << "Sorry, that number is too high, please pick another one!" << endl;
		cin.clear();
		cin >> y;																	
	}
	cout << "You chose :" << x;
	cout << " and " << y << endl;
	cout << "The end result is: " << x*y << endl;
	while (!GetAsyncKeyState(VK_F1) & 0x1);

	return 0;
}
 
Last edited:

TBA

Newbie
Full Member
Oct 1, 2012
23
307
1
Unless you didnt want the { }.. in that case if you wanted to be asked to input a number (x) 3 times and it to be cleared by cin.clear() twice then asks you for y then your code you have is fine..
I got bored and kinda redid the code to how maybe you wanted it..
C++:
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
	int x, y, xx, yy;//Declaring x,y,xx,yy
	xx =  32700;
	yy = -32700;
	cout << "Enter the first number you'd like to multiple\n";
	cin >> x;
	while (x > xx)// a whhile loop.. catches if x is > xx
	{// loops till x < xx
		cout << "Sorry the number you entered is too big try agian\n";
		cin.clear();
		cin >> x; 
	}
	while (x < yy)//loops till x > yy
	{
		cout << "Sorry the number you entered is too small try agian\n";
		cin.clear();
		cin >> x;
	}
	int i; // Declaring i as an int
	for (i = 0; i <= 3; i++) // for loop loops till i <=3
	{
		cin.clear();
		cin >> x;
		while (x > xx)// Loops till  x < xx;
		{
			cout << "Sorry the number you entered is too big try agian\n";
			cin.clear();
			cin >> x;
		}
		while (x < yy) //Loops till x > yy
		{
			cout << "Sorry the number you entered is too small try agian\n";
			cin.clear();
			cin >> x;
		}
			i++;// adds i
	}
	cout << "Enter the second number you'd like to multiple\n";
	cin >> y;
	int u;// Declaring u as an int
	while (y > xx) // Again while loop
	{
		cout << "Sorry the number you entered is too big try agian\n";
		cin.clear();
		cin >> y;
	}
	while (y < yy)// while loop
	{
		cout << "Sorry the number you entered is too small try agian\n";
		cin.clear();
		cin >> y;
	}
	for (u = 0; u <= 3; u++) // same for loop as before but with u
	{
		cin.clear();
		cin >> y;
		while (y > xx)// while loop again
		{
			cout << "Sorry the number you entered is too big try agian\n";
			cin.clear();
			cin >> y;
		}
		while (y < yy)//while loop again
		{
			cout << "Sorry the number you entered is too small try agian\n";
			cin.clear();
			cin >> y;
		}
		u++;
	}
	cout << "You chose :" << x;
	cout << " and " << y << endl;
	cout << "The end result is: " << x*y << endl;
	Sleep(2000);// Sleep for 2000 miliseconds
	//while (!GetAsyncKeyState(VK_F1) & 0x1);
	return(0);
}
Also one more thing
You do NOT have to use cin.clear()
Because everytime you have cin << x; its creating a new value for x
 

tvojama

uz42&4fd
Meme Tier VIP
Dank Tier Donator
Apr 1, 2015
377
2,498
10
All you had to do was enter in { } after your if statements
Also the bad thing about this is if you enter a number higher or lower then 32700 or -32700 two it will accept it because it doesnt loop to check if its higher or lower again.
Thank you, and I know it didn't loop to check is it higher or lower because I'm adding stuff as I'm learning, I added sinvclear just for a test to see if it do what I want it to do. And thank you for your redone code ^_^
 

TBA

Newbie
Full Member
Oct 1, 2012
23
307
1
Thank you, and I know it didn't loop to check is it higher or lower because I'm adding stuff as I'm learning, I added sinvclear just for a test to see if it do what I want it to do. And thank you for your redone code ^_^
No problem glad to have helped :)
 

bitm0de

Newbie
Full Member
Feb 28, 2016
19
358
2
Unless you didnt want the { }.. in that case if you wanted to be asked to input a number (x) 3 times and it to be cleared by cin.clear() twice then asks you for y then your code you have is fine..
I got bored and kinda redid the code to how maybe you wanted it..
C++:
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
	int x, y, xx, yy;//Declaring x,y,xx,yy
	xx =  32700;
	yy = -32700;
	cout << "Enter the first number you'd like to multiple\n";
	cin >> x;
	while (x > xx)// a whhile loop.. catches if x is > xx
	{// loops till x < xx
		cout << "Sorry the number you entered is too big try agian\n";
		cin.clear();
		cin >> x; 
	}
	while (x < yy)//loops till x > yy
	{
		cout << "Sorry the number you entered is too small try agian\n";
		cin.clear();
		cin >> x;
	}
	int i; // Declaring i as an int
	for (i = 0; i <= 3; i++) // for loop loops till i <=3
	{
		cin.clear();
		cin >> x;
		while (x > xx)// Loops till  x < xx;
		{
			cout << "Sorry the number you entered is too big try agian\n";
			cin.clear();
			cin >> x;
		}
		while (x < yy) //Loops till x > yy
		{
			cout << "Sorry the number you entered is too small try agian\n";
			cin.clear();
			cin >> x;
		}
			i++;// adds i
	}
	cout << "Enter the second number you'd like to multiple\n";
	cin >> y;
	int u;// Declaring u as an int
	while (y > xx) // Again while loop
	{
		cout << "Sorry the number you entered is too big try agian\n";
		cin.clear();
		cin >> y;
	}
	while (y < yy)// while loop
	{
		cout << "Sorry the number you entered is too small try agian\n";
		cin.clear();
		cin >> y;
	}
	for (u = 0; u <= 3; u++) // same for loop as before but with u
	{
		cin.clear();
		cin >> y;
		while (y > xx)// while loop again
		{
			cout << "Sorry the number you entered is too big try agian\n";
			cin.clear();
			cin >> y;
		}
		while (y < yy)//while loop again
		{
			cout << "Sorry the number you entered is too small try agian\n";
			cin.clear();
			cin >> y;
		}
		u++;
	}
	cout << "You chose :" << x;
	cout << " and " << y << endl;
	cout << "The end result is: " << x*y << endl;
	Sleep(2000);// Sleep for 2000 miliseconds
	//while (!GetAsyncKeyState(VK_F1) & 0x1);
	return(0);
}
Also one more thing
You do NOT have to use cin.clear()
Because everytime you have cin << x; its creating a new value for x
I think you are confused about what clear() does, because that is NOT what std::ios::clear() means. It has nothing to do with the value, and everything about the streams state. clear() effectively sets back the ios state to the goodbit, and this IS required if the object sets the failstate from a failure, but before calling clear() it would make more sense to check this fail state first.

If the goodbit is never set after the failbit is set, the object remains in a useless state, regardless of whether input is valid or not.

https://www.cplusplus.com/reference/ios/ios/clear/
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods