Clearing input..?

Is there a way to clear user input?

Page 1 of 1

8 Replies - 783 Views - Last Post: 17 January 2010 - 09:11 AM Rate Topic: -----

#1 Astraeus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 23
  • View blog
  • Posts: 205
  • Joined: 17-November 09

Clearing input..?

Posted 16 January 2010 - 06:08 PM

Ohai. I've been having a problem with an ATM program I've been working on. There is the obvious 3 attempts to enter the pin number, then it exits. However, the problem I've been having is that if you enter a wrong pin number, you cannot enter the correct one. Even if you do enter it, it still mistakes it as being wrong. Is there a way to clear user input..?

Snippet of user input and the three attempts:

#include "BankATM.h"
using namespace std;
int main()
{
	
	char ch;

	string s;
	string BankTask;
	
	int Bank_Pin;
	int Pin_Counter = 0;
	int Bank_Task_Num;
	int *Ba;

	float a;
	float b;

	do{
		cout << "\nEnter bank pin here : ";
		//Gets pin from user.
		do{
			//do{
			ch=char(getch());


			if(int(ch) !=13 && int(ch) != 8){
				cout << '*';
				s+=ch;

			}
		}while(int(ch)!=13);

		stringstream(s) >> Bank_Pin;

		if(Bank_Pin != 1234){
			Pin_Counter++;
			cout << "\n\nAccess Denied. Attempts ("
			<< Pin_Counter << ") Attempt Recorded!";
			if (Pin_Counter == 3){
				cout << "\nAccess Denied.";
				Sleep(500);
				exit(0);
			}
		}
		else{
			cout << "\nit worked.";
		}
	}while(Bank_Pin != 1234);
//Code unrelated to this problem.



Thank you for reading.

This post has been edited by Astraeus: 16 January 2010 - 06:10 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Clearing input..?

#2 carltech  Icon User is offline

  • What did you call me?
  • member icon

Reputation: 28
  • View blog
  • Posts: 997
  • Joined: 19-October 07

Re: Clearing input..?

Posted 16 January 2010 - 06:14 PM

if you mean clearing the console screen there is no standard way. if your on windows you can usesystem("cls");
Was This Post Helpful? 0
  • +
  • -

#3 Astraeus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 23
  • View blog
  • Posts: 205
  • Joined: 17-November 09

Re: Clearing input..?

Posted 16 January 2010 - 06:15 PM

No, not cls.. As an example: So i enter 4567 instead of 1234. It records it, but then if i enter 1234, it still says it's incorrect.
Was This Post Helpful? 0
  • +
  • -

#4 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1046
  • View blog
  • Posts: 4,449
  • Joined: 09-June 09

Re: Clearing input..?

Posted 16 January 2010 - 06:17 PM

cin.sync();


Was This Post Helpful? 0
  • +
  • -

#5 Astraeus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 23
  • View blog
  • Posts: 205
  • Joined: 17-November 09

Re: Clearing input..?

Posted 16 January 2010 - 06:18 PM

Ah ok. ^^ Thank you.
Was This Post Helpful? 0
  • +
  • -

#6 Chaos Mange  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 68
  • Joined: 23-December 09

Re: Clearing input..?

Posted 16 January 2010 - 06:19 PM

Make your pin a variable. Like:

   int pin = 1234;

   //cin the pin  to enter here

   // if statements here

   cin >> pin; // changing the value




It should work.


EDIT: I am on a different page then you sir. XD I read that completely differently than I should have.

This post has been edited by Chaos Mange: 16 January 2010 - 06:23 PM

Was This Post Helpful? 1
  • +
  • -

#7 Astraeus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 23
  • View blog
  • Posts: 205
  • Joined: 17-November 09

Re: Clearing input..?

Posted 16 January 2010 - 06:33 PM

Solved. Thank you Chaos. Null String worked.
Was This Post Helpful? 0
  • +
  • -

#8 Chaos Mange  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 68
  • Joined: 23-December 09

Re: Clearing input..?

Posted 16 January 2010 - 06:46 PM

View PostAstraeus, on 16 Jan, 2010 - 05:33 PM, said:

Solved. Thank you Chaos. Null String worked.

Welcome, demos gave me the idea Wednesday. I ran into the same thing.
Was This Post Helpful? 0
  • +
  • -

#9 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 854
  • View blog
  • Posts: 2,338
  • Joined: 20-August 07

Re: Clearing input..?

Posted 17 January 2010 - 09:11 AM

View PostAstraeus, on 17 Jan, 2010 - 01:33 AM, said:

Solved. Thank you Chaos. Null String worked.

By 'null string' do you mean a null-terminated 'C' string (i.e. char[])? if so, then whatever 'worked' will also work with a C++ string too. You shouldn't ever need to use C strings in C++.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1