Revise Programming Challenge 3 to use an array of Product objects instad of two parallel arrays. The Product class will need member variables to hold a product name and a quantity.
Challenge 3 says to make a program that allows a store to keep track of their sales, and sales for the 5 different salsa types.
After much trying, I can't seem to get said program to work. I've commented the errors, and what they are. Here's what I've got so far:
#ifndef SALSA_H
#define SALSA_H
class Salsa
{
private:
void getTotal();
void getHigh();
void getLow();
int count;
int total;
int high;
int low;
int flavor;
public:
void getSold();
};
#endif
#include "Salsa.h"
#include <iostream>
#include <string>
using namespace std;
void Salsa::getSold()
{
for (count = 0; count < 5; count++)
{
cout << "Jar sold last month of ";
cout << count + 1;
cin >> flavor[count]; //Get error saying subscript array or pointer type
while (flavor[count] <= 0) // Get error saying subscript array or pointer type
cout << "Jars sold must be greater than or equal to 0.";
cout << "Re-enter jars sold for last month ";
cin >> flavor[count];
cout << endl;
}
}
Salsa::getTotal();
Salsa::getHigh();
Salsa::getLow();
}
void Salsa::getTotal()
total = 0;
for (count = 0; count < 5; count++)
total += flavor[count];
cout << "Total Sales: " << total << endl;
}
void Salsa::getHigh()
{
highest = flavor[0];
int index = 1;
for (count = 0; count < 5; count++)
if (flavor[count] > highest)
{
highest = flavor[count];
index = count + 1;
}
cout << "High Seller: " << flavor << endl;
}
void Salsa::getLow()
{
lowest = flavor[0];
int index = 1;
for (count = 0; count < 5; count++)
if (flavor[count] < lowest)
{
lowest = flavor[count];
index = count + 1;
}
cout << "Low Seller: " << flavor << endl;
}
#include "Salsa.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int SALS_FLAV = 5;
string flavor[SALS_FLAV] = { "mild", "medium", "sweet", "hot", "zesty" };
Salsa sold;
for (int index = 0; index < SALS_FLAV; index++)
getSold(flavor[SALS_FLAV]); // Get error saying 'getSold' identifier not found
sold.getSold();
return 0;
}
Aucun commentaire:
Enregistrer un commentaire