Parallel vectors9/3/2023 ![]() BTW you define "x" as a char and initialize it with a numeric value, not the correct way. If you check the value of "x" before you call the function it should be "0\0" which is not what you want. Line 5 is where you get the letter to send to the function yet you call the function using "x" not "choiceAgain" as you should. ![]() The only problem with line 8 is how you call the function. Line 7 uses "iomanip", that you did include, to format how the number that the function will return. My research says that "toupper" needs the header file "ctype.h" to be included at the beginning of the program. Line 6 makes sure you have an upper case letter to send to the function. Better to chose a variable name that is easy to understand in the beginning. Just my thoughts on that the name of the variable does not matter as long as you understand it, but think about looking at this program six months from now when you discover that some of your variable names do not make any sense. It is a bit misleading, how can you "choiceAgain" when you have not made a first choice, "choice" would be a better name for the variable, IMHO. Std::cout << std::fixed << std::showpoint << std::setprecision(2) Ĭout << "Cost of inventory for class" << " " << choiceAgain << " is" << " $" << costForClass(choiceAgain, p) << endl Īlthough it works, "choiceAgain" is not the best name for this variable. Once you get the "countB圜lass" function working correctly this will give you something to follow for the"costForClass" function. The function will only execute once because you have no means to loop through the vector. The switch will not work because "cls" does not contain a useful value, so it will check every case and exit the switch without doing anything. Not to keep this line its just for testing. Std::cout << " " << p.number << " " << p.cls << " " << p.ohb << " " << p.cost << std::endl Īfter the definition of "p" will give you an idea of what is in "p". I have not tried it yet, but I think putting this So what is its use? And does it need to be there?Īgain you have defined "Parts p ", but never do anything with it, so when you have the line total += p.ohb ohb has no value and total might equal whatever garbage is at the memory location of ohb. Again you are sending two parameters the first parameter is never used. it should beįor ( int i = 0 i & pVector). The for loop online 153 will only have one iteration due to the middle condition. Line 144 "Parts p " has no real use in this function because all the information you will need is in "pVector". You have a second parameter here that is never used, so unless you have a later use for this I do not see any use for it right now. Void countB圜lass( const vector &pVector, vector &classCounts) Of course it is not printing the correct numbers. adding up the amounts of cost // choice 1 double total = 0 įor ( int i = 0 i &pVector, vector &classCounts) While (inputFile > p.number > p.cls > p.ohb > p.cost) Void displa圜ounts( const vector & classCounts) which part had the lowest cost // choice 5 String lowestCost( const vector &pVector) Which part had the highest cost // choice 4 String highestCost( const vector &pVector) Added amount for each individual class // choice 3 Displays letter and amount // choice 2ĭouble costForClass( char classIn, const vector & pVector) InputFile.open( "parts.txt") // Opens required textĬout > p.number > p.cls > p.ohb > p.cost) void countB圜lass( const vector &pVector, vector &classCounts) ĭouble costForClass( char classIn, const vector & pVector) function prototypes bool readFile(vector &pVector) ĭouble totalCost( const vector &pVector) #include #include #include #include #include using namespace std
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |