JUST BEEPING NOT WORKING

Hello everyone.My name is Raymond and I am an Indian student from Kuwait.In my school they dont teach in depth about programming in C++
I am also very new to this site
can U please help me out with the program
This is a program used to testnavigating with arrows in a menu driven program

whenever I run it it works but when I select any option it just producing a 'sound' but it doesnt print(cout) anything on the screen....I really dont know what to do ........can anyone help me out please?



P.s.This program is just to test the arrow navigation and doesnt really modify,delete or add a new record but only prints stuff on screen



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103


#include<fstream.h>    //for reading and writing files
#include<conio.h>      //for clrscr()
#include<string.h>     //for string characters
#include<stdio.h>      //for gets and puts function
#include<process.h>    //for exit function
#include<iomanip.h>    //for setw function
#include<dos.h>        //for delay and sleep function

class word
{
 int man;
 public:
 void add();
};
void word::add()
{
 cout<<"GOD IS GREAT";
};

void main()
{ char ch,c=0,che=16;
  int i=1,j=16;
  do
  {
  gotoxy(35,11);cout<<"MAIN MENU";
  gotoxy(35,12);cout<<"___________";
  gotoxy(13,16);cout<<"A.ADD";
  gotoxy(13,18);cout<<"B.DISPLAYALL";
  gotoxy(13,20);cout<<"C.DISPLAYINDIVIDUAL";
  gotoxy(13,22);cout<<"D.DELETE";
  gotoxy(52,16);cout<<"E.MODIFY";
  gotoxy(52,18);cout<<"F.SALE";
  gotoxy(52,20);cout<<"G.EXIT";
 gotoxy(26,27);cout<<"USE ARROWS TO NAVIGATE";
 gotoxy(i,j);cout<<che;
 do
 {ch=getch();
     if(ch==72&&j-2>=16)
 {gotoxy(i,j);cout<<c;j-=2;gotoxy(i,j);cout<<che<<"\b";}
 if(ch==75&&i-13>=13)
  {gotoxy(i,j);cout<<c;i-=39;gotoxy(i,j);cout<<che<<"\b";}
 if(ch==77&&i+39<=52)
  {gotoxy(i,j);cout<<c;i+=39;gotoxy(i,j);cout<<che<<"\b";}
 if(ch==80&&j+2<=22)
  {gotoxy(i,j);cout<<c;j+=2;gotoxy(i,j);cout<<che<<"\b";}
 }while(ch!=13);
 cout<<"\a";
 switch(ch)
     {
 case 13:
       if(i==11&&j==16)
       {
         clrscr();
        void add();
        cout<<"ADDED";
        cout<<"\a\a\a\a\a\a\a\a\a\a";
        break;
       }
       else if(i==11&&j==18)
       {
        cout<<"DISPLAYEDALLMAN";
        cout<<"\a\a";
        break;
       }
       else if(i==11&&j==20)
       {
        cout<<"DISPLAYED INDIVIDUAL";
        cout<<"\a";
        break;
       }
       else if(i==11&&j==22)
       {
        cout<<"DELETED";
        cout<<"\a";
        break;
       }
       else if(i==50&&j==16)
       {
        cout<<cout<<"modified";
        cout<<"\a";
        break;
       }
       else if(i==50&&j==18)
       {
        cout<<"SOLD";
        cout<<"\a";
        break;
       }
       else if(i==50&&j==20)
       {
        cout<<"EXIT";
        break;

       }

      }
       }while(ch);
 }


Did you hear about escape sequences? The start with the '\'

'\a' does indeed beep. Read more:

http://en.wikipedia.org/wiki/Escape_sequences_in_C


What are you trying to achieve here:
1
2
3
        void add(); // This declares a function. It does not call it
        cout<<"ADDED";
        cout<<"\a\a\a\a\a\a\a\a\a\a"; // ?? 
I am sorry
@coder777:OK I get it but why doesnt it print whatever have written in the cout ?? pls tell me how to correct this ?
The switch seems to be unnecessary. ch cannot be anything but 13.

for i you add/subtract only 39. So there's no way that i will ever become 11 or 50
Last edited on
Can U pls modified the code for me....I cannot understant what u r saying pls?
Let me see if I understand what you are trying to do.

You want to display a menu.
On the menu, there are several ways to select an option.

1) The user could just type a letter 'a'..'g' or 'A'..'G'.

2) The user could use the up and down arrow keys to move the cursor to one of the lines and press Enter.

Also, I assume you are using an old Turbo C compiler. (Because if you are not, the following information will not help.)

You should be aware that the state of CS in India is 15-20 years out of date. If you have time, get yourself a modern compiler and play with it using modern C++ standards. Knowing how to use it will put you ahead.

The input should be aware of the location of the cursor relative to the top of the menu. It should also not permit the cursor to move outside of those bounds.

Personally, I would use text to display the "cursor", and leave the actual blinking thing down in the corner.

I don't currently have an old copy of Turbo C installed, so I cannot test the following code for correctness. You may have to fix a thing or two to make it work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
void draw_main_menu()
{
  // display the menu here
}

int get_main_menu_choice()
{
  // This keeps track of the currently selected item
  int current = 0;

  // The cursor needs to be placed at the first item in the menu
  gotoxy(13,16);

  // Now we need to wait for the user to press something correct
  while (true)
  {
    switch (getch())
    {
      // First we will handle the user pressing a letter
      case 'a': case 'A': return 0;
      case 'b': case 'B': return 1;
      ...
      case 'g': case 'G': return 6;

      // Next, we will handle arrow keys. 
      // When the user presses an arrow key, the first thing you will 
      // get from getch() is either 0 (on older hardware) or 0xE0 (on newer
      // hardware). So if either of these was the key we got, then the next
      // thing we get from getch() will be the "extended key code" for the
      // arrow key (and other special keys).
      case 0: case 0xE0:
        switch (getch())
        {
          // up arrow key
          case 72:
            if (current > 0)  // (don't go above the first item)
            {
              current -= 1;
              gotoxy(current+13,16);
            }
            break;

          // down arrow key
          case 80:
            if (current < 6)  // (don't go below the 6th item)
            {
              current += 1;
              gotoxy(current+13,16);
            }
            break;

          // all other special keys -- ignored
          default: break;
        }
        break;

      // If the user presses Enter, choose the current menu option
      case 13: return current;

      // All other keys -- ignored
      default: break;
    }
  }
}

void add()
{
  clrscr();
  cout << "If God wills it.\n";

  gotoxy(1,20);
  cout << "Press any key" << flush;
  switch (getch()) { case 0: case 0xE0: getch(); }
}

int main()
{
  bool done = false;

  while (!done)
  {
    draw_main_menu();
    switch (get_main_menu_choice())
    {
      case 0: add(); break;
      case 1: display_all(); break;
      case 2: display_individual(); break;
      ...
      case 6: done = true; break;
    }
  }

  cout << "Good-bye!\n";
  return 0;
}

That should work for you. Remember, I may have made a small mistake in there somewhere, but you should be able to figure it out.

Once you get that working, there are a couple more issues you should consider.

The first is that the draw menu, get menu choice, and main functions all must know something about what the menu looks like. Specifically, every function must know that the menu has seven items, and what those items are numbered. You can use an enumeration to help.

Wife just came home -- I've got to go now. (We're going out.)

[edit]
The second is hardcoding the location of the menu is problematic. You should be able to place the menu at a coordinate given by argument to the menu functions.

The last is that it might be worth making the menu itself a data-driven object. That is, create a struct that represents the menu and its items. Then pass that "menu" struct to the menu functions.

Hope this helps.
Last edited on
Topic archived. No new replies allowed.