this program doen't depug need help

This program doen't depug need help

Need help debugging

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
#include <iostream>
#include <string>

using namespace std;
	


int main()
{
	char yn = 'y';

	while (yn == 'y')
	{

		string names[20];

		bool reservStatus[20];
		int tableNum = 1;
		

		for(int i=0; i < 20; i++)
		{
			reservStatus[i] = false;
		}
		if (reservStatus[tableNum] == true)
		{
			// reserved
		}
		else        
		{
			// not reserved
		}

		reservStatus[tableNum] = true;
		reservName[tableNum] = name;

		cout << "run it? (y/n)?";
		cin >> yn;
	}
}
Last edited on
closed account (3qX21hU5)
Well it has to compile first to be able to debug it ;p. Lets run through the compiler errors first, then we can get to the logic errors if there are any.


1) Line 21: int tableNum = 1; and Line 17: int tableNum;. Two variable in the same scope that have the same name. You can't have this delete the one on line 17.

2)Line 15: int reservName and Line: 38 reservName[tableNum] = name;. You are trying to use a subscript on a integer variable which you can't do. Subscripts are made for containers like strings (Kind of a container), vectors, arrays, lists, ect.

Now I am assuming your want to store names in a container and what was what you were trying to do. So I would recommend you change Line 16: int name; to something like vector<string> names; or if you like arrays string names[20];. Notice that I also changed the variable type to a string (Since I am assuming it will hold name's in it). You had it as a integer which will only hold numbers and it would have failed if you had tried to store a string in it like "John".

You also got some other things wrong, but I won't go into that right now.

What I need from you now that the compiler errors are fixed is what you want the program to do? What is it suppose to do? What are you stuck on? What is it doing wrong?

If you can give us more info on what your stuck on and what the program is doing wrong we can help push you in the right direction.

Hope this helps.
i made the changes that you recommended

i still have variable declaration problems, i tried to declare string name;, but it doesn't work

the program is suppose to create table reservations for a restaurant storing the table number and name

this is the assignment


create a reservation system for a restaurant. The restaurant has 20 tables. Here is the functionality required for this system (you may want to display a menu and let user choose options 1 to 4, make sure to put your program in a loop so program does not exit until user chooses menu 4):

1- Reserve a Table
User needs to input the table number (Tables are numbered from 0 to 19). If the table is not available (reserved), inform the user that the selected table is not available. If the table is available, then ask for the name (name is a single word, no space) and mark the table as reserved.

2- Clear Reservation
User needs to input the table number (Tables are numbered from 0 to 19). If the table is not reserved, inform the user that the selected table is already available (nothing to clear). If the table is reserved, mark it as available. That table is no longer reserved.

3- Report
Prints out the state of each table. Each table is printed on a separate line -- so your report will print out 20 rows. If reserved, it will print out the name on the reservation next to the table number. If available, it should print out "available".

4- Exit Program.

You can keep everything in the main function. I would recommend keeping a two arrays (parallel arrays!), both are size 20, one of type boolean (reserved or not) and the other one of type string (name on reservation if reserved).
Last edited on
closed account (3qX21hU5)
For now I will give you this framework to work off of. I just threw it together really quick so you might want to change it around a bit to fit your needs or how you want the program to work. Hopefully it gives you somewhere to start.


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
#include <iostream>
#include <string> // You need this to use a string

using namespace std;

int main ()
{
    /* Declare all the variables you will need here.
    *  Like a container of strings to hold the names,
    *  another container to hold the table numbers,
    *  ect.
    */
    int menuChoice;
    string name;

    while (true)
    {
        cout << "Please enter a selection" << endl;

        // This is telling the user the menu
        cout << "Reserve a Table - 1" << endl;
        cout << "Clear Reservation - 2" << endl;
        cout << "Order a Report - 3" << endl;
        cout << "Exit Program - 4" << endl;

        // Place to hold the input for the menu
        cin >> menuChoice;

        // Menu options.
        // The switch will hold all your code, you can either put the code
        // for each menu choice directly in the switch cases or make seperate
        // functions for each of them.
        switch (menuChoice)
        {
            case 1:
                // This is where you will put the code that does
                // stuff for number 1: Reserve a table.
                break;

            case 2:
                // Code for Clear Reservation
                break;

            case 3:
                // Code for the Report
                break;

            case 4:
                // Terminates the program, I did this one for you.
                return 0;
        }
    }

    return 0;
}


If you have any specific questions please let me know and I will do my best to answer them for you. Also as for your string question look at the code, you have to include the string header to be able to use the string type.
Last edited on
Topic archived. No new replies allowed.