C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 2nd, 2012, 04:15 AM
wakilnikzad wakilnikzad is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 1 wakilnikzad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 55 sec
Reputation Power: 0
Backspace key reads a character instead of removing password in C++ program

Hello dears,
I've began learning C++ / Object Oriented Programming and am facing a problem in assigning password to my following program,
When I type the password it does not have any problem but when I want to remove a character using backspace or delete keys instead of removing they print characters. Need Your Kind Help!

This is my program coding:

Code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<dos.h>
class project
{
private:
	int i,oop,dld,dbc,ca,eng,total;
	float percent;
	char name[10]; char fname[10]; char program[4];
public:
	void design(void)
	{
	for(i=0;i<=40;i++)
	{
	gotoxy(5+i,2);
	cout<<"\xdb";
	gotoxy(5+i,4) ;
	cout<<"\xdb";
	gotoxy(5+i,23) ;
	cout<<"\xdb";
	gotoxy(5+i,25)  ;
	cout<<"\xdb";
	}
	for(i=0;i<=22;i++)
	{
	gotoxy(5,2+i);
	cout<<"\xdb";
	gotoxy(45,2+i);
	cout<<"\xdb";
	}
	gotoxy(11,3);
	cout<<" Detailed Marks Certificate ";
	gotoxy(9,24);
	cout<<"For Help contact DB Administrator ";
	}
	void input(void)
	{
	gotoxy(12,6);
	cout<<"1. OOP:";
	gotoxy(12,8);
	cout<<"2. DLD:";
	gotoxy(12,10) ;
	cout<<"3. DBC:";
	gotoxy(12,12);
	cout<<"4. C.Alg:";
	gotoxy(30,6);
	gotoxy(12,14);
	cout<<"5. Eng:";
	gotoxy(30,6);
	cout<<"Name:";
	gotoxy(30,8);
	cout<<"F/Name:";
	gotoxy(30,10);
	cout<<"Program:";
	gotoxy(9,17);
	for(i=0;i<=32;i++)
	{
	cout<<"\xdb";
	}
	gotoxy(14,18);
	cout<<"Total:";
	gotoxy(9,19);
	cout<<"Percentage:";
	gotoxy(14,20);
	cout<<"Grade:";
	}
	void call(void)
	{
	gotoxy(19,6);
	cin>>oop;
	gotoxy(19,8);
	cin>>dld;
	gotoxy(19,10);
	cin>>dbc;
	gotoxy(21,12);
	cin>>ca;
	gotoxy(19,14);
	cin>>eng;
	gotoxy(36,6);
	cin>>name;
	gotoxy(37,8);
	cin>>fname;
	gotoxy(39,10);
	cin>>program;
	total=oop+dld+dbc+ca+eng;
	gotoxy(20,18);
	cout<<total;
	percent=total/5;
	gotoxy(20,19);
	cout<<percent;
		if ((percent<=100)&&(percent>=90))
		{
		gotoxy(20,20);
		cout<<"A";
		}
		else
		{
		if((percent<90)&&(percent>=80))
		{
		gotoxy(20,20);
		cout<<"B";
		}
		else
		{
		if((percent<80)&&(percent>=70))
		{
		gotoxy(20,20);
		cout<<"C";
		}
		else
		{
		if ((percent<70)&&(percent>=50))
		{
		gotoxy(20,20);
		cout<<"D";
		}
		else
		{
		gotoxy(20,20);
		cout<<"Fail";
		}
		}
		}
		}

	}
};
void main(void)
{
start:
textbackground(4);
textcolor(7);
clrscr();
gotoxy(30,7);
cout<<"Log_In_Page";
gotoxy(5,9);
cout<<"User_Name:";
gotoxy(5,11);
cout<<"Password:";

char name1[10]={"kardan"};

char name2[10];
char pass1[10]={"google"};
char pass2[10]={""};
gotoxy(15,9);
cin>>name2;
gotoxy(14,11);
int i=0;
char ch;
cout<<pass2;
while((ch=getch())!='\r')
{
if(ch!='\b')
{
putch('x');
pass2[i]=ch;
i++;
}
//gotoxy(13+i,11);
if(getch()==8)
{
gotoxy(13+i,11);
//putch('\0');
pass2[i-1]='\0';
i--;
cout<<'\0';
}
}
if(strcmp(name1,name2)==0 && strcmp(pass1,pass2)==0)
{
textbackground(0);
textcolor(7);
clrscr();
gotoxy(25,15);
cout<<"Loading.....";
int j;
for(j=0;j<=40;j++)
{
gotoxy(10+j,16);
cout<<"\xdb";
delay(100);
}
clrscr();
gotoxy(15,15);
cout<<"Press any key to coontinue..." ;
getch();
clrscr();
project obj;
obj.design();
obj.input();
obj.call();
}
else
{
clrscr();
gotoxy(5,15);
cout<<"\n Invalid Password";
gotoxy(5,18);
cout<<"Try Again";
getch();
goto start;
}
getch();
}

Reply With Quote
  #2  
Old December 2nd, 2012, 12:21 PM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,839 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 18 h 47 m 43 sec
Reputation Power: 1774
Post your code between [code][/code] tags. NOBODY is going to wade through 200+ lines of crappy code just to find out what you did wrong.

And please make sure you copy from your editor (to get some indentation - we hope), and DO NOT just ctrl-c/ctrl-v the code from post #1.

This is how code should look when posted. Keep pressing "Preview Changes" until you get it right.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Last edited by salem : December 2nd, 2012 at 02:16 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Backspace key reads a character instead of removing password in C++ program

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap