Help Please!

closed account (G2zhRXSz)
Can someone tell me why I keep getting error messages? Please and thank you!!

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

void displayMenu();
bool readData(string inventoryNames[], float inventoryCost[]);
void displayData(string inventoryNames[], float inventoryCost[]);
void mkIndex(string inventoryNames[], char index[]);
void copyRightInfo();

int main()
{
void copyRightInfo();
{
cout << "*****************************************************************\n";
cout << "The Apothecary Shop\n";
cout << "This program will read in the shop’s \n";
cout << "Data and Display that data, along with its associated\n";
cout << "index table.\n";
cout << "Program Developed by: \n";
cout << "*****************************************************************\n";
}

bool readData(string inventoryNames[], float inventoryCost[]);
{
bool readFile = false;
//Finish all the code Program 7-7
const int ARRAY_SIZE = 10; // Array size
int numbers[ARRAY_SIZE]; // Array with 10 elements
int count = 0; // Loop counter variable
ifstream inputFile; // Input file stream object

// Open the file.
inputFile.open("TenNumbers.txt");

// Read the numbers from the file into the array.
while (count < ARRAY_SIZE && inputFile >> numbers[count])
count++;

// Close the file.
inputFile.close();

// Display the numbers read:
cout << "The numbers are: ";
for (count = 0; count < ARRAY_SIZE; count++)
cout << numbers[count] << " ";
cout << endl;
return 0;
//create and initailize your loop counter

//create your input file pointer - i.e. ifstream
inputFile.open("data.txt");

//open the file - the file with strings

//test to see if file exists - if (fileName)

//if test is true then you want to loop and read in all values from file
//dont forget to use getline(filePointer, YourArray[index])

//close your file

//initialize your loop counter

//create your input file pointer - i.e. ifstream for your inventory costs
inputFile.open("inventory.txt");

//open the file - the file with float values

//test to see if file exists - if (fileName)

//if test is true then you want to loop and read in all values from file
//using regulare >>

//close your file

return readFile;
}
//while loop
void mkIndex(string inventoryNames[21], char index[21]);
{
//creat a for loop to go through each element
//assign the index element kount to the first letter of inventory Names kount

}
const int arraySize = 9;
bool readFile = false;
//Declare an array
int myNumbers[arraySize];//one dimensional array - for each dimension to access or print the whole array you will need one loop
int kount = 0;
//create a file pointer
ifstream inputFile; //input file pointer
//point to the file - open the file
inputFile.open("data.txt");

if (inputFile)//Test to see if file opened
{
for (kount = 0; kount < arraySize; kount++)
{
inputFile >> myNumbers[kount];//or try cin instead of inputfiel if it doesnt work
}

readFile = true;
}
else
cout << "Error...Reading file...\n";


if(readFile)
//Print all the elements in my array
for (int kount = 0; kount < 5; kount++)
{
cout << myNumbers[kount] << " ";
}

return 0;
}
Last edited on
Does the error message contain any information? Maybe the actual error message is telling you what's wrong.
Maybe the actual error message is telling you what's wrong.

Idk, seems like a long shot.

Anyway, you've made function prototypes (declarations) and never actually defined them. You've also looped through an array that you never set it's values equal to anything, so you're getting garbage output on this line: cout << numbers[count] << " ";


Also, always put code tags around your code: (at the beginning ->) [.code] [./code] (<- at the end) (and remove the periods).
@Repeater......I don't know why, but that response had me laughing nearly to tears.

....let me try, too.


@koaken

We've seen this many times. The process involves a repeating cycle of feedback. We compile, there are errors, we fix the errors and try again. Eventually this process fixes the problem or there's just no hope left and all is lost.

Nope....I can't do it. Not like @Repeater. (I'm seeing the scene of a patient professor, hands folded, trying hard to be understanding of the freshman's questions)

Seriously, WHAT did it say?

....and use code tags!

They look like this


[code]
Your code goes here
[/code]
Last edited on
@koaken

I created the following input file TenNumbers.txt
1  2  3  4   5  6   7   8   9  10


I compiled and ran your program (against my better judgement). It produced the following output and appeared to finish quite happily ... when it reached return 0; Of course, you have a lot of code after that which it never gets a chance to try ... (or run into any run-time errors in).

*****************************************************************
The Apothecary Shop
This program will read in the shop's 
Data and Display that data, along with its associated
index table.
Program Developed by: Margaret Grosso
*****************************************************************
The numbers are: 1 2 3 4 5 6 7 8 9 10 


What would you like it to do?



!!!!! CODE TAGS - CODE TAGS - CODE TAGS - CODE TAGS !!!!
Last edited on
closed account (G2zhRXSz)
I am trying to make the program read in the shop's
inventory, display all the current items and display an index of the current items available.
Then I am trying to create a menu to allow the user to display the items, the index or exit. The menu needs to loop until user is
ready to exit
closed account (G2zhRXSz)
@niccolo I am actually in my third year of my Bachelor's program. I just happened to get a professor that has a lot going on in their personal life and it has affected their ability to teach this semester. I am only making this post because I am having to teach myself an entire course and am just in desperate need of help.
One big problem is that you seem to have written the code thinking that C++ lets you define functions inside of functions. Here's an example with my comments describing what is actually happening. Unfortunately, C++ syntax makes this particular mistake VERY easy to make.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int
main()
{
    void copyRightInfo();   // redeclare function copyRightInfo
    {  // start a new block of code within function main(). This block will execute once.
        cout << "**************************************************************\
***\n";
        cout << "The Apothecary Shop\n";
        cout << "This program will read in the shop’s \n";
        cout << "Data and Display that data, along with its associated\n";
        cout << "index table.\n";
        cout << "Program Developed by: \n";
        cout << "**************************************************************\
***\n";
    } // end of the new block. 


Another problem that I see multiple times is confusing the count of items in an array with the index used to print the individual items. For example:
1
2
3
4
5
6
7
8
9
10
11
12
    // Read the numbers from the file into the array.
    while (count < ARRAY_SIZE && inputFile >> numbers[count])
        count++;

    // Close the file.
    inputFile.close();

    // Display the numbers read:
    cout << "The numbers are: ";
    for (count = 0; count < ARRAY_SIZE; count++)
        cout << numbers[count] << " ";
    cout << endl;

The underlined code is wrong. First, by using count as the array index, you lose the number of items that were read into the array. Second, by looping up to ARRAY_SIZE, you print items that you might never have read. That code should be:
1
2
3
4
    cout << "The numbers are: ";
    for (int i = 0; i < count; i++)  // new variable i is the index for this loop. The loops ends at count
        cout << numbers[i] << " ";
    cout << endl;


Can you post the actual assignment? This will help us figure out what the code is supposed to do.

This version still doesn't work but I think it's closer to what you're trying to do.
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

void displayMenu();
bool readData(string inventoryNames[], float inventoryCost[]);
void displayData(string inventoryNames[], float inventoryCost[]);
void mkIndex(string inventoryNames[], char index[]);
void copyRightInfo();

int
main()
{
    const int arraySize = 9;
    bool readFile = false;
    //Declare an array
    int myNumbers[arraySize];	//one dimensional array - for each
				//dimension to access or print the
				//whole array you will need one loop 
    int kount = 0;
    //create a file pointer
    ifstream inputFile;		//input file pointer point to the file
				//- open the file
    inputFile.open("data.txt");

    if (inputFile)				 //Test to see if file opened
    {
	for (kount = 0; kount < arraySize; kount++) {
	    inputFile >> myNumbers[kount];	 //or try cin instead
						 //of inputfiel if it
						 //doesnt work 
	}

	readFile = true;
    } else
	cout << "Error...Reading file...\n";

    if (readFile)
	//Print all the elements in my array
	for (int kount = 0; kount < 5; kount++) {
	    cout << myNumbers[kount] << " ";
	}

    return 0;
}

void
copyRightInfo()
{
    cout << "*****************************************************************\n";
    cout << "The Apothecary Shop\n";
    cout << "This program will read in the shop’s \n";
    cout << "Data and Display that data, along with its associated\n";
    cout << "index table.\n";
    cout << "Program Developed by: \n";
    cout << "*****************************************************************\n";
}

bool
readData(string inventoryNames[], float inventoryCost[])
{
    bool readFile = false;
    //Finish all the code Program 7-7
    const int ARRAY_SIZE = 10;	// Array size
    int numbers[ARRAY_SIZE];	// Array with 10 elements
    int count = 0;		// Loop counter variable
    ifstream inputFile;		// Input file stream object

    // Open the file.
     inputFile.open("TenNumbers.txt");

     // Read the numbers from the file into the array.
     while (count < ARRAY_SIZE && inputFile >> numbers[count])
 	count++;

     // Close the file.
     inputFile.close();

     // Display the numbers read:
     cout << "The numbers are: ";
     for (int i = 0; i < count; i++)
 	cout << numbers[i] << " ";
     cout << endl;

    
     //create and initailize your loop counter

     //create your input file pointer - i.e. ifstream
     inputFile.open("data.txt");

     //open the file - the file with strings

     //test to see if file exists - if (fileName)

     //if test is true then you want to loop and read in all values from file
     //dont forget to use getline(filePointer, YourArray[index])
     //close your file

     //initialize your loop counter

     //create your input file pointer - i.e. ifstream for your inventory costs
     inputFile.open("inventory.txt");

     //open the file - the file with float values

     //test to see if file exists - if (fileName)

     //if test is true then you want to loop and read in all values from file
     //using regulare >>

     //close your file

     return readFile;
}

// //while loop
void
mkIndex(string inventoryNames[21], char index[21])
{
     //creat a for loop to go through each element
     //assign the index element kount to the first letter of inventory Names kount

}

@kroaken

@niccolo I am actually in my third year of my Bachelor's program. I just happened to get a professor that has a lot going on in their personal life and it has affected their ability to teach this semester. I am only making this post because I am having to teach myself an entire course and am just in desperate need of help.


I'm sympathetic, and I wasn't really aiming anything at you, it was just @Repeater, with something of a valid point, was just in a position to hit my funny bone.

@dhayden has much more pertinent help for you than I offered.

I'll try better.

Ok, in main, this line:

void copyRightInfo();

Looks like a function declaration, which you have correctly shown just above main in your declaration section. Unfortunately, there's no actual copyRightInfo() function defined. What appears in your text LOOKS to a human like what you intend as the definition of the copyRightInfo function, but it is contained inside the main function, and that's not allowed.

@dhayden thoughtfully exampled how the copyRightInfo function should appear. It is below and outside the main function.

@dhayden's example didn't happen to call the function, which would merely be a line like the following near or at the top of the main function, something like

1
2
3
4
5
6
int main()
{
copyRightInfo();

//....then the rest of the main function
} // <<<<<<<<<<<<<<<<<<<<<<<< this ends the main function 


Now we come to the read data function definition. The top line of that reads thus in your post:

1
2
3
4
5
6
7
8
9
10
11
12
bool readData(string inventoryNames[], float inventoryCost[]);
{
bool readFile = false;
//Finish all the code Program 7-7
const int ARRAY_SIZE = 10; // Array size
int numbers[ARRAY_SIZE]; // Array with 10 elements
int count = 0; // Loop counter variable
ifstream inputFile; // Input file stream object

//....................................the rest of the readData function

} // closes the readData function 


The initial problem here is the ";" in the first line. A function definition must take this form

1
2
3
4
void foo()
{

}


Note the absence of a ";" after "foo()". The semicolon would make the line a declaration, which by itself is ok (and you have that at the top of the text correctly), but here the text must proceed into the definition with an opening "{", not a ";"

It is an error you tend to repeat, which is why I detail it here.

In the case of mkIndex in your text we're left a bit puzzled. @dhayden worked that out by moving that code into main, but consider this simplified example of what your text does:

1
2
3
4
5
6
7
void mkIndex( string names[21], char index[21] );
{
}

const int arraySize = 9;

/////......more material here 


Here is that same error repeated (the misplaces ";" following the "mkIndex" signature line).

If one removes that ";", we now have the "{" as the next important character after the ")" closing the signature for mkIndex, but we have a different problem.

It is quickly closed after a few comments in your text. That's the close of the function.

From "const int arraySize = 9;" forward, what we have is text outside of a function body (it was closed by the "}" earlier).

That makes the declarations of arraySize, readFile, myNumbers, kount, and the others, GLOBAL declarations of variables. That's actually legal, but very likely not what you intend. It appears these are supposed be inside the mkIndex function, and should therefore appear just after the opening "{" and before the close "}", along with the rest of that code which follows.

By the time the text reaches "inputFile.open("data.txt")" in your text the compiler is going to complain that functions can't be called outside of function bodies like this, which is solved by merely moving that code into a function as @dhayden demonstrates by moving that into main.

At this point I've merely narrated some of @dhayden changes, partly to explain a bit as to why, motivated by seeing repeated simple syntax mistakes.

Somewhere at this pint @dhayden wisely pauses to hand it back to you.

For that I pose a short discussion about your plan (both questions and suggestions).

As @dhayden was trying to make sense of these syntax errors, then paused, I pick up at this point from you:

The menu needs to loop until user is ready to exit


This becomes your outermost design point. The menu is first to be presented (after the copyrightinfo), and controls all else.

Naturally, THAT is what really belongs in main - or at least a driver for it. In typical animation loops (which this is, essentially), what we usually do is the really simple outline:

1
2
3
4
5
6
7
8
int main()
{
 initialize();

 while( menuLoop() );

 // possibly a shutdown of resources when required, or just a goodbye
}


This may seem so simple as to be useless, but it describes your entire, overall plan quite simply. There is initialization (your copyrightinfo display in this case), then a presumed looping of the menu. "menuLoop() is a proposed function that would return a bool, "true" for all actions except an exit request by the user, at which point the application closes. This repeats menuLoop until exit is requested.

Exactly as you've said.

The function of menuLoop is not a loop - that is looped from main. It is ONE PASS through the loop. That is, print the menu, take the input, take action on the input (if valid and not an exit), return true for all except exit condition (return false then).

Typically one takes in a number from the menu list, and performs a switch, where each case calls whatever function relates to that choice.

There's where you start. That's how you "hang everything else" on this "framework".

See how that fits your overall goals and continue posting your updated code and questions as you proceed.

From there we can discuss a few points in further exchange.

For example, what is in "data.txt" and what is in "inventory.txt", and what is "TenNumbers.txt"?

How do these files relate to the inventory you're loading and processing?

Last edited on
closed account (G2zhRXSz)
Thank you all so much for all your help!!
data.txt contains:
2.3
5.5
7.75
5
4.5
5
8
2
2
5.35
8.5
4.25
6.35
4.25
8.25
2
3.25
1.25
2.33
3.65
4.65

inventory.txt contains:
Bilberry
Aloe Vera
Milk Thistle
Saint John's Wort
Saw Palmetto
Catnip
Valerian
Echinacea
Fennel
Ginko Biloba
Ginger
Mint
Angelica
Goldenseal
Evening Primrose Oil
Garlic
Black Cohosh
Witch Hazel
Chamomile
Feverfew
Ginseng

I should have included this in the original post, sorry guys!

This is the actual assignment:
PROBLEM: The Apothecary Shop. (20 pts)
Write the Apothecary Shop program. The shop owner needs a program to read in the shops
inventory, display all the current items and display an index of the current items available. Create a
menu to allow the user to display the items, the index or exit. The menu should loop until user is
ready to exit.
The program must use the functions defined below under Constraints. See Pseudo code for how the
main function will run.
You must use the two input files provided for you by your instructor for this project.
Input Validation: The program must check to see if the user enters a valid menu option.

Partial PSEUDO-CODE for main function - (one of many ways you can do your program)
Homework Assignment 6 Pool
COP2000 HOMEWORK ASSIGNMENT 7B 4
1. Declare and initialize your variables, this includes you arrays. Create your 1D arrays to store
your inventory names, inventory cost and the index of the inventory items. Create the 1D
arrays so that they will be able to store all the items in inventory. You will use a Boolean value
as a “flag” to indicate when you will exit the program whether it is because you did not read in
the file or the user wishes to exit.
2. Call the copyRightInfo() function
3. Call the readData() function – Do not forget to capture the returned value a bool, your flag
4. If flag is true call the mkIndex() function
5. Start While loop only if flag is true (Hint: the flag is the Boolean variable you declared, your flag)
i. Call the displayMenu function()
ii. Read in the menu input
iii. Validate the menu input using a switch or series of if statements for each case 1, 2 or 3
1. Case 1
a. Call the displayData() function
2. Case 2
a. display the index array with a for loop
3. Case 3
a. output an Exit Message
b. set bool flag to false
4. Default/Not 1-3
a. output an Error Message
6. End While Loop
CONSTRAINTS:
• NO GLOBAL VARIABLES ALLOWED. (Automatic -10)
- Note: This means that all your arrays must be declared inside of main.
• You must use: int main()
• The program must use local variables. (2 pts)
• All functions MUST be called by main. (3 pts)
• Output must be formatted properly and correct. (3 pts)
• Include a comment at the beginning of the program stating the purpose of the program,
your name, the date, and your class (1pt is for code organization and use of whitespace). (2
pts) This program MUST use the following functions: (10 pts)

NAME YOUR FUNCTIONS AS SHOWN BELOW (- 10 if not named correctly):

void displayMenu () - (1 pts) is passed no arguments and its only purpose is to display the
menu for the Apothecary shop program.
1. Display all inventory items
2. Display index of inventory items
3. Exit
Homework Assignment 6 Pool
COP2000 HOMEWORK ASSIGNMENT 7B 5
bool readData(string inventoryNames[], float inventoryCost[]) – (3 pts) is passed the 1D
array variables of the inventory items and the cost of the inventory items from main. The
read data function will open the Apothecary_Inventory.txt file and read in the inventory
data to the two 1D arrays respectively.
Note: Remember to close your file after you have read in all the data.
This function returns true or false to the main function after the it has completed if the file
was read in successfully or not. If the file was not read in successfully the program should
exit.
void displayData (string inventoryNames[], float inventoryCost[]) - (3 pts) is passed the 1D
array variables of the inventory items and the cost of the inventory items from main. The
displayData function must display all the inventory items available in a table format with
dollar signs and two decimal place precision for dollar values.

void mkIndex(string inventoryNames[], char index[])-(2 pts) ) is passed the 1D array
variables of the inventory items and the index from main. This function will pull the first
letter of each item from the inventoryNames array into the index array.

void copyRightInfo() - (1 pts) is NOT passed any values and returns no value. This function
outputs a description of the program and your information. Fill in your name as the
developer's name (i.e. replace "PUT YOUR NAME HERE" with your name).
*****************************************************************
The Apothecary Shop
This program will read in the shop’s
Data and Display that data, along with its associated
index table.
Program Developed by: "PUT YOUR NAME HERE"
*****************************************************************


One of the biggest problems I'm having is initializing my variables first, using flags, and using loops.
I need to create 3 cases as the assignment says. Do I need a for loop for case 1 and 3 as well?

Thank you all again, this is a HUGE help!
I'm reading what appears to be two related assignments, 7B-4 and 7B-5. Are you making two separate programs?

Based on what I see of your code, I'd like to suggest a fairly "clean" approach to get something started that lays out a structure for everything else that follows.

First, look at the end of my previous post about the menuLoop. Create that function, and create the required displayMenu function. In menuLoop, call the displayMenu function. In menuLoop, take in the user's selection. Form a switch, with cases for each entry in the menu (by number), and for the "exit" option, return false.

For all other options, leave the cases empty (use break for each though), and return true from the end of the menuLoop function.

Comment out any other existing function that gets in the way of compiling and getting that working.

We'll then expand on that.


Last edited on
closed account (G2zhRXSz)
Just one program, working on commenting it out now.
closed account (G2zhRXSz)
This is a sample out I made, does this help?
*****************************************************************
The Apothecary Shop
This program will read in the shop’s
Data and Display that data, along with its associated
index table.
Program Developed by: "Kendall"
*****************************************************************
Inventory Menu
-----------------------------
1. Display all inventory items
2. Display index of inventory items
3. Exit
<<<<<<<<<<<<< Inventory >>>>>>>>>>>>>

Bilberry $2.3
Aloe Vera $5.5
Milk Thistle $7.75
Saint John's Wort $5
Saw Palmetto $4.5
Catnip $5
Valerian $8
Echinacea $2
Fennel $2
Ginko Biloba $5.35
Ginger $8.5
Mint $4.25
Angelica $6.35
Goldenseal $4.25
Evening Primrose Oil $8.25
Garlic $2
Black Cohosh $3.25
Witch Hazel $1.25
Chamomile $2.33
Feverfew $3.65
Ginseng $4.65

Inventory Menu
------------------
1. Display all inventory items
2. Display index of inventory items
3. Exit

*****************************************************************
The Apothecary Shop
This program will read in the shop’s
Data and Display that data, along with its associated
index table.
Program Developed by: "Kendall"
*****************************************************************

Inventory menu
-----------------
1. Display all inventory items
2. Display index of inventory items
3. Exit

A, A, B, B, C, C, E, E, F, F, G, G, G, G, G, M, M, S, S, V, W

Inventory menu
-----------------
1. Display all inventory items
2. Display index of inventory items
3. Exit

Inventory menu
-----------------
1. Display all inventory items
2. Display index of inventory items
3. Exit

Invalid menu item entered... Enter a value from 1-3 >>

Inventory menu
-----------------
1. Display all inventory items
2. Display index of inventory items
3. Exit
Thank you for visiting the Apothecary Shop...
The output sample is helpful.

Do you have any advancement on the code at this point to post?
Thanks for the assignment text. It really helps a lot.

I see that you posted "Inventory.txt" and "data.txt" but the assignment's description of readData() mentions "Apothecary_Inventory.txt" and indicates that this one file will contain the inventory AND cost data.

Also, it appears that the program must declare the arrays to be exactly the right size to hold the data in the files. This unusual so you might want to verify it with the professor. If the arrays should be larger to allow more items then how do you know the actual number of items read? The required signature for readData() doesn't provide a place to pass back that number.

Here is a version based on the assignment description. Pay close attention to how I used the pseudocode for main to write the actual code. There are only two things that aren't exact translations of the pseudocode:
- the "willExit" flag is really a "run" flag. In other words, true means keep running and false means stop.
- I added a local variable for the user's menu choice.

I've also copied the descriptions of the other functions verbatim to the code and turned them into comments. This is a very simple and powerful technique to ensure that you do exactly what's required.

Because the of the confusion about whether there is one input file or two, I left readData empty for this version.

All that's left now is to write readData(), displayData() and mkIndex().
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

void displayMenu();
bool readData(string inventoryNames[], float inventoryCost[]);
void displayData(string inventoryNames[], float inventoryCost[]);
void mkIndex(string inventoryNames[], char index[]);
void copyRightInfo();

int
main()
{
    // 1. Declare and initialize your variables, this includes you arrays. Create your 1D arrays to store
    // your inventory names, inventory cost and the index of the inventory items. Create the 1D
    // arrays so that they will be able to store all the items in inventory. You will use a Boolean value
    // as a “flag” to indicate when you will exit the program whether it is because you did not read in
    // the file or the user wishes to exit.
    const int arraySize = 9;
    string inventoryNames[arraySize];
    float inventoryCosts[arraySize];
    char index[arraySize];
    bool run;			// the opposite of "willExit"
    
    // Local variables not specifically mentioned in the assignment
    unsigned choice;	       // the user's menu choice
    
    // 2. Call the copyRightInfo() function
    copyRightInfo();
    
    // 3. Call the readData() function – Do not forget to capture the returned value a bool, your flag
    run = !readData(inventoryNames, inventoryCosts);

    // 4. If flag is true call the mkIndex() function
    if (run) {
	mkIndex(inventoryNames, index);
    }
    
    // 5. Start While loop only if flag is true (Hint: the flag is the Boolean variable you declared, your flag)
    while (run) {
	// i. Call the displayMenu function()
	displayMenu();
	// ii. Read in the menu input
	cin >> choice;
	// iii. Validate the menu input using a switch or series of if statements for each case 1, 2 or 3
	switch(choice) {
	case 1:
	    // 1. Case 1
	    // a. Call the displayData() function
	    displayData(inventoryNames, inventoryCosts);
	case 2:
	    // 2. Case 2
	    // a. display the index array with a for loop
	case 3:
	    // 3. Case 3
	    // a. output an Exit Message
	    // b. set bool flag to false
	default:
	    // 4. Default/Not 1-3
	    // a. output an Error Message
	    cout << "invalid menu choice\n";
	}
    } // 6. End While Loop

    // CONSTRAINTS:
    // • NO GLOBAL VARIABLES ALLOWED. (Automatic -10)
    // - Note: This means that all your arrays must be declared inside of main.
    // • You must use: int main()
    // • The program must use local variables. (2 pts)
    // • All functions MUST be called by main. (3 pts)
    // • Output must be formatted properly and correct. (3 pts)
    // • Include a comment at the beginning of the program stating the purpose of the program,
    // your name, the date, and your class (1pt is for code organization and use of whitespace). (2
    // pts) This program MUST use the following functions: (10 pts)
}

// void displayMenu () - (1 pts) is passed no arguments and its only
// purpose is to display the menu for the Apothecary shop program.
// 1. Display all inventory items
// 2. Display index of inventory items
// 3. Exit
void displayMenu()
{
    cout << "1. Display all inventory items\n";
    cout << "2. Display index of inventory items\n";
    cout << "3. Exit\n";
}

// void copyRightInfo() - (1 pts) is NOT passed any values and returns
// no value. This function outputs a description of the program and
// your information. Fill in your name as the developer's name
// (i.e. replace "PUT YOUR NAME HERE" with your name).
// *****************************************************************
// The Apothecary Shop
// This program will read in the shop’s
// Data and Display that data, along with its associated
// index table.
// Program Developed by: "PUT YOUR NAME HERE"
// ***************************************************************** 
void
copyRightInfo()
{
    cout << "*****************************************************************\n";
    cout << "The Apothecary Shop\n";
    cout << "This program will read in the shop’s \n";
    cout << "Data and Display that data, along with its associated\n";
    cout << "index table.\n";
    cout << "Program Developed by: \n";
    cout << "*****************************************************************\n";
}

// The read data function will open the Apothecary_Inventory.txt file
// and read in the inventory data to the two 1D arrays respectively.
// Note: Remember to close your file after you have read in all the
// data.  This function returns true or false to the main function
// after the it has completed if the file was read in successfully or
// not. If the file was not read in successfully the program should
// exit.
bool
readData(string inventoryNames[], float inventoryCost[])
{
}

// displayData - (3 pts) is passed the 1D array variables of the
// inventory items and the cost of the inventory items from main. The
// displayData function must display all the inventory items available
// in a table format with dollar signs and two decimal place precision
// for dollar values.
void displayData (string inventoryNames[], float inventoryCost[])
{
}



// void mkIndex(string inventoryNames[], char index[])-(2 pts) ) is
// passed the 1D array variables of the inventory items and the index
// from main. This function will pull the first letter of each item
// from the inventoryNames array into the index array.
void
mkIndex(string inventoryNames[], char index[])
{
    //creat a for loop to go through each element
    //assign the index element kount to the first letter of inventory Names kount

}

Topic archived. No new replies allowed.