Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <iostream> #include <iomanip> #include <string> #include <fstream> #inc

ID: 3641495 • Letter: #

Question


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

const int PERSONS = 4;
const int SALES = 3;

enum {ENTER_SALES = 1, PRINT_ALL, EXIT};

int getMenuChoice();
void displayMenu();
void initi_Sale(int sale[PERSONS][SALES]);
void processChoice(int choice, int& sale_ID, int sale[PERSONS][SALES]);
void enterSales(int& sale_ID, int sale[PERSONS][SALES]);
void getID(int& sale_ID, int sale[PERSONS][SALES]);
void printAll(int sale[PERSONS][SALES]);
void printLine();
void printSpace();
void printDoubleLine();



int main()
{

int sale[PERSONS][SALES];
int choice;
int sale_ID;


initi_Sale(sale);

while((choice = getMenuChoice()) != EXIT)
{
processChoice(choice, sale_ID, sale);
}
return 0;
}

void initi_Sale(int sale[PERSONS][SALES])
{
for (int i = 0; i < PERSONS; i++)
{
for (int j = 0; j < SALES; j++)
{
sale[i][j] = 0;
}
}
}


int getMenuChoice()
{
int choice;
bool valid;

do
{
displayMenu();

cin >> choice;

if( cin.fail() || choice < 1|| choice > 3)
{
cin.clear();
valid = false;
cout << " !! Wrong input, please input 1-4 ";
printLine();
}
else
{
valid = true;
}
cin.ignore(100, ' ');
} while (!valid);

return choice;
}


void displayMenu()
{
printDoubleLine();
cout << " MENU ";
printLine();
printSpace();
cout << "1. Enter Sales "
<< "2 Print All "
<< "3. Exit ";
printLine();
printSpace();
cout << "Enter 1-3: ";
}


void processChoice(int choice, int& sale_ID, int sale[PERSONS][SALES])
{
if (choice == ENTER_SALES)
{
printSpace();
printDoubleLine();
printSpace();
cout << "Enter Sales ";
printSpace();
printLine();
printSpace();
enterSales(sale_ID, sale);
}
if (choice == PRINT_ALL)
{
printSpace();
printDoubleLine();
printSpace();
cout << "Print_All";
printSpace();
printLine();
printAll(sale);
}
}

void enterSales(int& sale_ID, int sale[PERSONS][SALES])
{

getID(sale_ID, sale);
}

void getID(int& sale_ID, int sale[PERSONS][SALES])
{
cout << "Salesperson ID: ";
cin >> sale_ID;

double sum = 0;

if (sale_ID == 1)
{
for (int i = 0; i < SALES; i++)
{
cout << "Sales of Product " << i + 1 <<": ";
cin >> sale[0][i];
sum = sum + sale[0][i]; //<<<<----------------------------------------------This right here!!!
}

}
if (sale_ID == 2)
{
for (int i = 0; i < SALES; i++)
{
cout << "Sales of Product " << i + 1 <<": ";
cin >> sale[1][i];
}
}
if (sale_ID == 3)
{
for (int i = 0; i < SALES; i++)
{
cout << "Sales of Product " << i + 1 <<": ";
cin >> sale[2][i];
}
}
if (sale_ID == 4)
{
for (int i = 0; i < SALES; i++)
{
cout << "Sales of Product " << i + 1 <<": ";
cin >> sale[3][i];
}
}

}


void printAll(int sale[PERSONS][SALES])
{
for (int i = 0; i < PERSONS ; i++)
{
for (int j = 0; j < SALES; j++)
{
cout << sale[i][j] << " ";
}
}
cout << endl;
}

void printDoubleLine()
{
for (int i = 0 ; i < 50 ; i++)
{
cout << "=";
}
cout << endl;
}

void printLine()
{
for (int i = 0 ; i < 50 ; i++)
{
cout << "-";
}
cout << endl;
}


void printSpace()
{
for (int i = 0 ; i < 50 ; i++)
{
cout << " ";
}
cout << endl;
}

Explanation / Answer

That is the correct way to sum up the sales for that particular person. I don't think I understand what you are trying to do. Copy and paste this code and see for yourself that the sum is correct. #include #include #include #include #include using namespace std; const int PERSONS = 4; const int SALES = 3; enum {ENTER_SALES = 1, PRINT_ALL, EXIT}; int getMenuChoice(); void displayMenu(); void initi_Sale(int sale[PERSONS][SALES]); void processChoice(int choice, int& sale_ID, int sale[PERSONS][SALES]); void enterSales(int& sale_ID, int sale[PERSONS][SALES]); void getID(int& sale_ID, int sale[PERSONS][SALES]); void printAll(int sale[PERSONS][SALES]); void printLine(); void printSpace(); void printDoubleLine(); int main() { int sale[PERSONS][SALES]; int choice; int sale_ID; initi_Sale(sale); while((choice = getMenuChoice()) != EXIT) { processChoice(choice, sale_ID, sale); } return 0; } void initi_Sale(int sale[PERSONS][SALES]) { for (int i = 0; i choice; if( cin.fail() || choice < 1|| choice > 3) { cin.clear(); valid = false; cout