Jun 13, 2007

C++ Program to scroll names by arrow keys

This program will ask user to input 10 names that will be array of strings and then user has to press a down arrow key or up arrow key to scroll down or upwards. If users presses a down arrow key then name will be scroll one by one on the screen. If user presses up arrow key then previous name will be displayed on the screen. If last name is displayed and users presses again down arrow key then beep sound will be generated and then noscrolling will be there. Same way if users is already at first name and if he presses up arrow key then also beep sound will be generated and no scrolling will occured.

#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<process.h>

main()
{
clrscr();
char name[10][10];

for (int i=0;i<=9;i++)
{
cout <<"enter any name";
cin >> name[i];
}

clrscr();
int ch;
i=0;
while(1)
{
ch = getch();
if (ch==65)
{
break;
}
if (i==-1)
{
i=0;
sound(700);
delay(100);
nosound();
}
if (i==10)
{
i=9;
sound(700);
delay(100);
nosound();
}

if (ch==80 && i>=0 && i<=10 && ch!=0)
{
gotoxy(50,12);
cout << name[i]<<" ";
name[++i];
}

if (ch==72 && i>=0 && i<=10 && ch!=0)
{
gotoxy(50,12);
cout << name[i]<<" ";
name[--i];
}

}
getch();
}

No comments:

Post a Comment

Infolinks In Text Ads

Total Pageviews

Powered by Blogger.

Dont Forget To Follow Us

Blog Archive