Doubts and Errors

Hi everyone. This is my first post - so please go a bit easy on me :P - See , i've been learning c++ for a major part of the year (last year) in school - and all students have to make this 'database management' project to accompany our school leaving exams - and i've made one - but the problem is that i got so engrossed in my other subjects - i totally forgot about this project - but i DID make a fairly functionable project earlier - a really library management system - but my teacher found plenty of errors in it - and didn't exactly tell me what to do about them .... So here's my code - could some please help me with this ?
i've got my leaving exam in less than a week - so i don't want to sound like an arrogant self centered idiot - please, its really urgent .......

What my teacher says -
-goto() should not be used in any case
-main() cannot be called from another function

How can i create 'recurring' menus otherwise ?

Also - i've seen that goto() is creating all the run time errors here -
If anyone can help - please post an example to go along with the text -
thank you so much !
Last edited on
Us5 wrote:
How can i create 'recurring' menus otherwise ?
What kind of control structure can you think of that allows you to repeat code over and over?
Honestly 350 lines of unindented code are too much to read (props for using code tags though).
Edited out the rest of the answer to see the OP answer to LB.
Last edited on
Please indent. Really. I don't want to manually indent 350 lines of code in my head.
Indenting makes it easier to read.
Thanks for the suggestions -
L B,maeriden & greenleaf800073
I'll remove the code - there's actually no need for that.

I don't know what i was doing last night - 350 lines of un-indented code - really thats just plain stupid - I'll be as precise as possible -
@L B - loops.I framed my question incorrectly - you know what the problem is - once i go into a menu - say in this example -
1
2
3
4
5
6
7
8
9
//let me call this page 1 
int n;
do  
 {
   cout<<"1-Menu 1 \n2-Menu 2 \n3-Exit ";
   cin>>n; 
  } while(n!=3);
 
 


Now suppose menu 1 takes me to a 'new' page (using clrscr();)
how do i come back to page1 ?

That's what i want to know.
Last edited on
Let your menus be functions. When you want to to exit a menu, you exit the function.

You want to display a sub-menu, call a function to handle the submenu. When you exit the submenu, you return to the calling menu. When you exit the main menu, return to main and let main exit.
What the guy above said.
how about this

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
void function1() {
  //task here
}

void function2() {
  //task here
}

void function3() {
  //task here
}

int main() {

  int num1, num2, num3;

  while (true) {

    cout << "Enter a number. -1 to skip all loops" << endl;
    cin >> num3;

    if (num3 == -1) break;

    function1();

    while(true) {

      cout << "Enter a number. -1 to skip the last loop" << endl;
      cin >> num2;

      if (num2 == -1) break;

      function2();

      while(true) {

        cout << "Enter a number. -1 to skip this loop" << endl;
        cin >> num1;

        if (num1 == -1) break;

        function1();

      } //brace for function1();

    } //brace for function2();

  } //brace for function3();

  return 0;

} //for main 
@Mark Anthony Laureta

Instead of all those nested infinite loops & repeated tests, it would be much better to have a switch statement.

It is however a good idea to have functions - each case in the switch should call a function.

The switch could be enclosed in a while loops like this:

1
2
3
4
5
6
7
8
9
bool Quit = false;

whlie(!Quit) {
//switch statement here

//user wants to quit
Quit = true;
}


HTH
cout << "Enter 1 for function 1, etc...";
cin >> input;

switch(input)
{
case 1:
function1();
break;
case 2:

and so on.
Topic archived. No new replies allowed.