Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I learned c++ a while ago and then stopped coding for a while. I got back into it this year and honed my skills. I am trying to make a hotel managment system for practice, but I am geting all these crazy errors. here is part of the code. P.S. I am working with visual studio for the first time and don't know to much about it.

C++
  1  #include "reservation_existing_user.h"
  2  #include <iostream>
  3  using namespace std;
  4  
  5  
  6  void reservation::main_menu() {
  7  	int action_1;
  8  	account main;
  9  
 10  	cout << "Welcome to My bank! Press 1: to make a new account."  << endl;
 11  	cin >> action_1;
 12  
 13  	if (action_1 == 1) {
 14  		add(main);
 15  		print(main);
 16      }
 17  
 18  	
 19  	
 20  
 21  
 22  
 23  }
 24  
 25  
 26  
 27  void reservation::add(account& acc) {
 28  	
 29  	char n[6], p[12];
 30  
 31  	cout << "What is your name: ";
 32  	cin.width(6);
 33  	cin >> n[6];
 34  	cout << endl << "What is your Phone Number: ";
 35  	cin.width(12);
 36  	cin >> p[12];
 37  
 38  	Accounts* node1 = new Accounts;
 39  
 40  	for (int i = 0; i < 6; i++) {
 41  		node1->Name_1[i] = n[i];
 42  	}
 43  	for (int j = 0; j < 12; j++) {
 44  		node1->Phone_1[j] = p[j];
 45  
 46  		
 47  	
 48  
 49  	if (acc == NULL) {
 50  		acc = node1;
 51  		node1->next = NULL;
 52  	}
 53  	else {
 54  		node1->next = acc;
 55  		acc = node1;
 56  	}
 57  }
 58  	void reservation::print;(account & acc) {
 59  	Accounts* loopptr = acc;
 60  	while (loopptr != NULL) {
 61  		cout << endl << "Name: " << loopptr->Name_1 << " Phone: " << loopptr->Phone_1 << endl;
 62  		loopptr = loopptr->next;
 63  	}
 64  
 65  
 66  }
 67  
 68  int main() {
 69  
 70  	reservation obj;
 71  
 72  	obj.main_menu();
 73  
 74  
 75  }
 76  
 77  #pragma once //header file
 78  
 79  #include <iostream>
 80  
 81  
 82  class reservation
 83  {
 84  private:
 85  	
 86  
 87  public:
 88  
 89  	struct Accounts {
 90  	 char Name_1[6];
 91  	 char Phone_1[12];
 92  
 93  		Accounts* next;
 94  	};
 95  	typedef Accounts* account;
 96  
 97  	struct Occupied {
 98  		int room_number;
 99  		char name;
100  		char phone;
101  		Occupied* next;
102  	};
103  	typedef Occupied* room;
104  
105  	void book_room(room& r, char n[30], char p[12]);
106  	void cancel_room(room& r, char n[30], char p[12]);
107  	void main_menu();
108  	void add(account& acc);
109  	void login();
110  	void print(account& acc);
111  
112  
113  
114  	
115  	
116  };


Errors:
Severity	Code	Description	Project	File	Line	Suppression State
Warning	C6200	Index '12' is out of valid index range '0' to '11' for non-stack buffer 'node1->Phone_1'.	Firstconsoleapplication	C:\Users\dznut\source\repos\Firstconsoleapplication\Firstconsoleapplication\reservation.cpp	38	
Severity	Code	Description	Project	File	Line	Suppression State
Warning	C6200	Index '6' is out of valid index range '0' to '5' for non-stack buffer 'node1->Name_1'.	Firstconsoleapplication	C:\Users\dznut\source\repos\Firstconsoleapplication\Firstconsoleapplication\reservation.cpp	40	
Severity	Code	Description	Project	File	Line	Suppression State
Warning	C6201	Index '6' is out of valid index range '0' to '5' for possibly stack allocated buffer 'n'.	Firstconsoleapplication	C:\Users\dznut\source\repos\Firstconsoleapplication\Firstconsoleapplication\reservation.cpp	32	
Severity	Code	Description	Project	File	Line	Suppression State
Warning	C6201	Index '12' is out of valid index range '0' to '11' for possibly stack allocated buffer 'p'.	Firstconsoleapplication	C:\Users\dznut\source\repos\Firstconsoleapplication\Firstconsoleapplication\reservation.cpp	34	
Severity	Code	Description	Project	File	Line	Suppression State
Warning	C6201	Index '12' is out of valid index range '0' to '11' for possibly stack allocated buffer 'p'.	Firstconsoleapplication	C:\Users\dznut\source\repos\Firstconsoleapplication\Firstconsoleapplication\reservation.cpp	38	
Severity	Code	Description	Project	File	Line	Suppression State
Warning	C6201	Index '6' is out of valid index range '0' to '5' for possibly stack allocated buffer 'n'.	Firstconsoleapplication	C:\Users\dznut\source\repos\Firstconsoleapplication\Firstconsoleapplication\reservation.cpp	40	
Severity	Code	Description	Project	File	Line	Suppression State
Warning	C6385	Reading invalid data from 'n':  the readable size is '6' bytes, but '7' bytes may be read.	Firstconsoleapplication	C:\Users\dznut\source\repos\Firstconsoleapplication\Firstconsoleapplication\reservation.cpp	32	
Severity	Code	Description	Project	File	Line	Suppression State
Warning	C6385	Reading invalid data from 'p':  the readable size is '12' bytes, but '13' bytes may be read.	Firstconsoleapplication	C:\Users\dznut\source\repos\Firstconsoleapplication\Firstconsoleapplication\reservation.cpp	34	

Severity	Code	Description	Project	File	Line	Suppression State
Warning	C6386	Buffer overrun while writing to 'node1->Phone_1':  the writable size is '12' bytes, but '13' bytes might be written.	Firstconsoleapplication	C:\Users\dznut\source\repos\Firstconsoleapplication\Firstconsoleapplication\reservation.cpp	38	
Severity	Code	Description	Project	File	Line	Suppression State
Warning	C6386	Buffer overrun while writing to 'node1->Name_1':  the writable size is '6' bytes, but '7' bytes might be written.	Firstconsoleapplication	C:\Users\dznut\source\repos\Firstconsoleapplication\Firstconsoleapplication\reservation.cpp	40	


What I have tried:

I have tried taking suggestions from the visual studio but it only confuses me more. I have looked solutions up and still can't find a way. Please Help, I really want to learn more about c++, and completing projects like these are the best way to do it.
Posted
Updated 23-Feb-22 2:53am
v3
Comments
Richard MacCutchan 23-Feb-22 8:57am    
You are using invalid values for your array indexes. Array indexes start at zero, so an array with 6 elements has index values 0, 1, 2, 3, 4 and 5. Index value 6 is beyond the end of the array.

One thing that immediately stands out is that main is the name of the function that is invoked when your program starts up. Using it as a variable name may therefore cause a lot of errors. Try changing it to something else, like principal, and see what happens. I also have no idea what account, add, and print are. Presumably you've defined them, but you haven't shown us their definitions.
 
Share this answer
 
One problem you have is an unterminated string. I am surprised Visual C++ did not tell you that. The string is
C++
cout << "Welcome to My bank! Press 1: to make a new account.  << endl;
I don't know why you can't copy the error messages either. I selected some with the left mouse button, clicked the right button, and then selected copy so I can paste these from code I broke on purpose to generate an error :
Quote:
1>D:\Repos\TestApp\Source\BatteryDlg.cpp(197,6): error C2065: 'batterylife': undeclared identifier
1>D:\Repos\TestApp\Source\BatteryDlg.cpp(200,43): error C2065: 'batterylife': undeclared identifier
 
Share this answer
 
v2
This should compile, however we dont know what is account, Account, etc

reservation_existing_user.h
C++
//New File of name reservation_existing_user.h
#pragma once //header file

#include <iostream>


class reservation
{
private:
	

public:

	struct Accounts {
	 char Name_1[6];
	 char Phone_1[12];

		Accounts* next;
	};
	typedef Accounts* account;

	struct Occupied {
		int room_number;
		char name;
		char phone;
		Occupied* next;
	};
	typedef Occupied* room;

	void book_room(room& r, char n[30], char p[12]);
	void cancel_room(room& r, char n[30], char p[12]);
	void main_menu();
	void add(account& acc);
	void login();
	void print(account& acc);

};

//End of File


C++
#include "reservation_existing_user.h"
#include <iostream>
using namespace std;


void reservation::main_menu() {
	int action_1;
	account main;

	cout << "Welcome to My bank! Press 1: to make a new account."  << endl;
	cin >> action_1;

	if (action_1 == 1) {
		add(main);
		print(main);
    }
}

void reservation::add(account& acc) {
	
	char n[6], p[12];

	cout << "What is your name: ";
	cin.width(6);
	cin >> n[6];
	cout << endl << "What is your Phone Number: ";
	cin.width(12);
	cin >> p[12];

	Accounts* node1 = new Accounts;

	for (int i = 0; i < 6; i++) {
		node1->Name_1[i] = n[i];
	}
	for (int j = 0; j < 12; j++) {
		node1->Phone_1[j] = p[j];

    	if (acc == NULL) {
    		acc = node1;
    		node1->next = NULL;
        	}
    	else {
    		node1->next = acc;
    		acc = node1;
    	}
    }
}

void reservation::print(account & acc) {
    Accounts* loopptr = acc;
    while (loopptr != NULL) {
    	cout << endl << "Name: " << loopptr->Name_1 << " Phone: " << loopptr->Phone_1 << endl;
    	loopptr = loopptr->next;
    }
}

int main(void) {

	reservation obj;

	obj.main_menu();

    return 0;
}
 
Share this answer
 
Quote:
Why am I getting these errors that don't make sense

Usually, the most important error is the first one.
First correction, replace:
C++
cout << "Welcome to My bank! Press 1: to make a new account.  << endl;

with
C++
cout << "Welcome to My bank! Press 1: to make a new account."  << endl;
 
Share this answer
 
To add to what the others say, this may help next time you get a compilation error: How to Write Code to Solve a Problem, A Beginner's Guide Part 2: Syntax Errors[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900