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.
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.