help please

I am using Microsoft Visual Studios,

Your program will be creating 10 library books. Each library book will have a title, author and publishing year. Each library book will be stored as a structure and your program will have an array of library books (an array of structures).

You will create a corresponding array of book genres: Mystery, Romance, Fantasy, Technology, Children, etc. If the first element of the array is storing information about a book titled: "More about Paddington", then the corresponding first element of book genre would indicate 'Children'.

The user of your program should be able to select what they want to do from a menu of the following things and your program needs to do what the menu selection indicates:

* Print the entire list of library books (including the title, author, publishing year and book genre)

* Display a count of how many books exist per genre

* Find and display all books where the publishing year is greater than the year user put in

* Print the titles of the books where the Genre may be indicated by a 'C' for Children, or 'M' for Mystery


here is what I have:

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// LibraryBooksNickoleSmith.cpp : This file contains the 'main' function. Program execution begins and ends there.
/*
*******************************************************************************************************************
*****************************************
	   ** Heading Comments:
	   ** Name: Nickole Smith
	   ** Date: 10/3/18
	   ** Purpose : Create an array and structure program for library books.
*******************************************************************************************************************
*******************************
	   ** Algorithm:
	   ** 0. No input from user.
	   ** 1. Create structure and array for book title, author (first and last name), year, and genres.
	   ** 2. Create system to put books in order from users input.
	   ** 3. Output information from users input.
*******************************************************************************************************************

*/


#include "pch.h"
#include <iostream>
using namespace std;

	int numBookGenre;
	int romance(numBookGenre);
	int technology(numBookGenre);
	int fantasy(numBookGenre);
	int scify(numBookGenre);
	int children(numBookGenre);
	int thriller(numBookGenre);
	int Mystery(numBookGenre);

	struct Book
	{
		char bookTitle;
		char authorFirstName;
		char authorLastName;
		char bookGenre;
		char bookYear;
	};

	void printEes(Book[], int);
   
	int main()
	{
	int numBooks;
	cout << "how many books? \n";
	cin >> numBooks;

	// create array for books.

	Book books[numBooks];

	for (int i = 0; i < numBooks; i++) {

		cout << "Please enter book title. \n";
		cin >> books[i].bookTitle;
		cout << "Author's first name. \n";
		cin >> books[i].authorFirstName;
		cout << "Author's last name. \n";
		cin >> books[i].authorLastName;
		cout << "What type of genre is the book?";
		cin >> books[i].bookGenre;
		cout << "What year was it published?";
		cin >> books[i].bookYear;
	}
	printEes(books, numBooks);

	void printEes(Book books[], int size)
	{
		for (int i = 0; i < size; i++) {
			cout << books[i].bookTitle << endl;
			cout << books[i].authorFirstName << " "
				<< books[i].authorLastName << endl;
			cout << books[i].bookGenre << endl;
			cout << books[i].bookYear << endl;
		}
		switch (books[i].bookGenre) {

			case childrens:
			cout << "C ";

		case Mystery:
			cout << "M ";

		case Fantasy:
			cout << "F ";

		case romance:
			cout << "R ";

		case Technology:
			cout << "Tech ";
		}
	}

	
}

I keep getting errors and I don't understand.

errors:

Error (active) E0028 expression must have a constant value LibraryBooksNickoleSmith C:\Users\smith\Desktop\CSC - Nikki\LibraryBooksNickoleSmith\LibraryBooksNickoleSmith\LibraryBooksNickoleSmith.cpp 53

Error (active) E0065 expected a ';' LibraryBooksNickoleSmith C:\Users\smith\Desktop\CSC - Nikki\LibraryBooksNickoleSmith\LibraryBooksNickoleSmith\LibraryBooksNickoleSmith.cpp 71

Error (active) E0169 expected a declaration LibraryBooksNickoleSmith C:\Users\smith\Desktop\CSC - Nikki\LibraryBooksNickoleSmith\LibraryBooksNickoleSmith\LibraryBooksNickoleSmith.cpp 96

Error C2131 expression did not evaluate to a constant LibraryBooksNickoleSmith c:\users\smith\desktop\csc - nikki\librarybooksnickolesmith\librarybooksnickolesmith\librarybooksnickolesmith.cpp 53

Error C2601 'printEes': local function definitions are illegal LibraryBooksNickoleSmith c:\users\smith\desktop\csc - nikki\librarybooksnickolesmith\librarybooksnickolesmith\librarybooksnickolesmith.cpp 71

Error C2065 'i': undeclared identifier LibraryBooksNickoleSmith c:\users\smith\desktop\csc - nikki\librarybooksnickolesmith\librarybooksnickolesmith\librarybooksnickolesmith.cpp 79

Error C2065 'childrens': undeclared identifier LibraryBooksNickoleSmith c:\users\smith\desktop\csc - nikki\librarybooksnickolesmith\librarybooksnickolesmith\librarybooksnickolesmith.cpp 81

Error C2131 expression did not evaluate to a constant LibraryBooksNickoleSmith c:\users\smith\desktop\csc - nikki\librarybooksnickolesmith\librarybooksnickolesmith\librarybooksnickolesmith.cpp 81

Error C2131 expression did not evaluate to a constant LibraryBooksNickoleSmith c:\users\smith\desktop\csc - nikki\librarybooksnickolesmith\librarybooksnickolesmith\librarybooksnickolesmith.cpp 84

Error C2065 'Fantasy': undeclared identifier LibraryBooksNickoleSmith c:\users\smith\desktop\csc - nikki\librarybooksnickolesmith\librarybooksnickolesmith\librarybooksnickolesmith.cpp 87

Error C2131 expression did not evaluate to a constant LibraryBooksNickoleSmith c:\users\smith\desktop\csc - nikki\librarybooksnickolesmith\librarybooksnickolesmith\librarybooksnickolesmith.cpp 87

Error C2131 expression did not evaluate to a constant LibraryBooksNickoleSmith c:\users\smith\desktop\csc - nikki\librarybooksnickolesmith\librarybooksnickolesmith\librarybooksnickolesmith.cpp 90

Error C2065 'Technology': undeclared identifier LibraryBooksNickoleSmith c:\users\smith\desktop\csc - nikki\librarybooksnickolesmith\librarybooksnickolesmith\librarybooksnickolesmith.cpp 93

Error C2131 expression did not evaluate to a constant LibraryBooksNickoleSmith c:\users\smith\desktop\csc - nikki\librarybooksnickolesmith\librarybooksnickolesmith\librarybooksnickolesmith.cpp 93
Last edited on
closed account (E0p9LyTq)
I keep getting errors

1. What is your compiler?

2. What are the errors you are getting?

PLEASE learn to use code tags, it will make reading and commenting on your source code MUCH easier.

HINT: you can edit your post and add code tags.

http://www.cplusplus.com/articles/jEywvCM9/
Does that help any?
closed account (E0p9LyTq)
The problem is you left out some code, so the line numbers in the errors doesn't match up with the line numbers in your source.

You are defining your printEes(books, numBooks) function (lines 48-83) within the body of main(). That is illegal.

After you try to call the function. That is illegal.

Error C2065 'i': undeclared identifier 81

Your for loop defines a local i that is out of scope when the loop ends: lines 50-56. Your switch tries to access a variable that is out of scope.

Your "undeclared identifier" errors in your switch. Create an enum that declares the names, or use ints for the cases.

Posting less than the full code, including the #include headers, makes it harder to track down what might be the cause(s) of some errors.
I have posted the full code and the full errors. I fixed one error that you pointed out.
Your way of creating an array on line 53 is not valid in C++ - just create one with size 10;
Your program will be creating 10 library books.


Also the book genre should be stored in a separate array not in the book struct.
1
2
3
4
5
6
7
8
	struct Book
	{
		char bookTitle;
		char authorFirstName;
		char authorLastName;
		char bookGenre;
		char bookYear;
	};


I don't know of any books with a title of one letter, and the only people whose names have one letter work for MI5.

I suggest that you use std::string rather than char for your data members.
Line 53
53 Book books[numBooks];

^ This is not a valid way to create an array.
Line 68 printEes(books, numBooks);


I thought we always provided provided functions return type too even DURING FUNCTION PROTOTYPING
Don't make that mistake again
Also as lastchance said...

struct Book
{
char bookTitle;
char authorFirstName;
char authorLastName;
char bookGenre;
char bookYear;
};


I don't know of any books with a title of one letter, and the only people whose names have one letter work for MI5.

I suggest that you use std::string rather than char for your data members.


Use string variables instead of char variables
Topic archived. No new replies allowed.