R
R
Reslyukov Alexander2021-06-14 22:41:06
C++ / C#
Reslyukov Alexander, 2021-06-14 22:41:06

How to fix the following errors?

Hello, again I am with my mistakes, this time on the pluses.

[Error] name lookup of 'i' changed for ISO 'for' scoping [-fpermissive]
[Note] (if you use '-fpermissive' G++ will accept your code)

#include <iostream>
#include <string>
#include <windows.h>
using namespace std;

class L_Book {
private:
  string name_book, autor; int pages;
  public:
  void AddBook(string a, string b, int c) {
    name_book = a;
    autor = b;
    pages = c;
  } 
  void GetAllBooks() {
    cout << "Book Name : \t" << name_book << endl << "Name Autor : \t" << autor <<endl << "Pages : \t" << pages << endl;
  }
} ;

void main() {
  string a, b; int c; bool soft = true; short menu, kol_books;
  L_Book book [500];
  setlocale (LC_ALL, "rus");

  //////////////STARTED
  while (soft == true) {
    system ("cls");
    cout << "\t 1) Добавить книгу" << endl << "\t 2) Список всех книг" <<endl;
    cin >> menu;

    if (menu == 1) {
      system ("cls");
      cout << ("Сколько книг хотите добавить? "); cin >> kol_books;
      for (int i = 0; i < kol_books; i++)
        system ("cls");

        cout << "Название книги: "; cin >> a, cout << endl;
        cout << "Имя автора: "; cin >> b; cout << endl;
        cout << "Количество страниц: "; cin >> c; cout << endl;
        book[i].AddBook ( a, b, c);
      }
      cout << "Успешно добавлено." << endl;
      Sleep (3000);

    }
         if (menu == 2) { 
         	system ("cls");
         	for (int i = 0; i < kol_books; i++) {
         		book[i].GetAllBooks();
         		Sleep(1000);
         	}
         	Sleep (3000);
         }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yokozuna, 2021-06-15
@Alexandr_202

The line does
book[i].AddBook ( a, b, c);
not declare a variable value.
If this block is included in the contents of the for loop, then there will be no errors:

for (int i = 0; i < kol_books; i++) {
                system("cls");

                cout << "Название книги: ";
                cin >> a, cout << endl;
                cout << "Имя автора: ";
                cin >> b;
                cout << endl;
                cout << "Количество страниц: ";
                cin >> c;
                cout << endl;
                book[i].AddBook(a, b, c);
            }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question