Question

Have Corporate Sales for 6 divisions and their quarterly sales figures. The issue is the error...

Have Corporate Sales for 6 divisions and their quarterly sales figures. The issue is the error function where I am unable to have user reinput the same quarterly amount without going to the next quarter input. This has affected the total sales for the company.

/*****************************************

This program gathers sales information

for six divisions and displays the total

sales for each division and total company.

*****************************************/

#include<iostream>

using namespace std;

// Classs division sales

class DivSales

{

private:

// Variables

int qrtSales[4];

static double totalSales;

public:

// DivSales();

void addQrtSales(int, int, int, int);

int sales(int);

static double getSales()

{

return totalSales;

}

};

// addQrtSales function

void DivSales::addQrtSales(int s1, int s2, int s3, int s4)

{

qrtSales[0] = s1;

qrtSales[1] = s2;

qrtSales[2] = s3;

qrtSales[3] = s4;

totalSales = totalSales + s1 + s2 + s3 + s4;

}

// Sales function

int DivSales::sales(int n)

{

int value = qrtSales[n];

return value;

}

// Validate input

void error()

{

cout << "\nYou have entered an invalid value\n";

system("pause");

}

// Initialize totalSales

double DivSales::totalSales = 0.00;

int main()

{

DivSales ds[6];

int i, j;

for (i = 0; i < 6; i++)

{

int s1, s2, s3, s4;

// Get input

cout << "\nEnter Sales Division: " << i + 1 << endl;

cout << "\nEnter Q1 Sales: ";

cin >> s1;

if (s1 < 0) error();

cout << "\nEnter Q2 Sales: ";

cin >> s2;

if (s2 < 0) error();

cout << "\nEnter Q3 Sales: ";

cin >> s3;

if (s3 < 0) error();

cout << "\nEnter Q4 Sales: ";

cin >> s4;

if (s4 < 0) error();

ds[i].addQrtSales(s1, s2, s3, s4);

}

cout << "-----------------------------------\n";

cout << "\t" << "Q1" << "\t" << "Q2" << "\t" << "Q3" << "\t" << "Q4" << endl;

cout << "-----------------------------------\n";

for (i = 0; i < 6; i++)

{

cout << "DIV" << i + 1;

for (j = 0; j < 4; j++)

{

cout << "\t" << ds[i].sales(j);

}

cout << endl;

}

cout << "-----------------------------------\n";

cout << "\nTotal All Division Sales for the Year: "

<< ds[0].getSales() << endl;

cout << endl;

system("pause");

return 0;

}

Output:

Enter Sales Division: 1

Enter Q1 Sales: -1

You have entered an invalid value
Press any key to continue . . .

Enter Q2 Sales: -1

You have entered an invalid value
Press any key to continue . . .

Enter Q3 Sales: 100
....

Enter Sales Division: 6

Enter Q1 Sales: 100

Enter Q2 Sales: 100

Enter Q3 Sales: 100

Enter Q4 Sales: 100
-----------------------------------
Q1 Q2 Q3 Q4
-----------------------------------
DIV1| -1 -1 100 100
DIV2| 100 100 100 100
DIV3| 100 100 100 100
DIV4| 100 100 100 100
DIV5| 100 100 100 100
DIV6| 100 100 100 100
-----------------------------------

Total All Division Sales for the Year: 2198

Press any key to continue . . .

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is updated code below: (We have to use while loop to iterate until user inputs correct value)

#include<iostream>

using namespace std;

// Classs division sales

class DivSales

{

private:

// Variables

int qrtSales[4];

static double totalSales;

public:

// DivSales();

void addQrtSales(int, int, int, int);

int sales(int);

static double getSales()

{

return totalSales;

}

};

// addQrtSales function

void DivSales::addQrtSales(int s1, int s2, int s3, int s4)

{

qrtSales[0] = s1;

qrtSales[1] = s2;

qrtSales[2] = s3;

qrtSales[3] = s4;

totalSales = totalSales + s1 + s2 + s3 + s4;

}

// Sales function

int DivSales::sales(int n)

{

int value = qrtSales[n];

return value;

}

// Validate input

void error()

{

cout << "\nYou have entered an invalid value\n";

system("pause");

}

// Initialize totalSales

double DivSales::totalSales = 0.00;

int main()

{

DivSales ds[6];

int i, j;

for (i = 0; i < 6; i++)

{

int s1, s2, s3, s4;

// Get input

cout << "\nEnter Sales Division: " << i + 1 << endl;

bool isCorrect1=true;

//Here we added a loop that will continue to iterate till a correct input is provided

//Same method is followed to get all inputs correctly

while(isCorrect1)

{

cout << "\nEnter Q1 Sales: ";

cin >> s1;

if (s1 < 0)

error();

else

{

isCorrect1 = false;

bool isCorrect2=true;

while(isCorrect2)

{

cout << "\nEnter Q2 Sales: ";

cin >> s2;

if (s2 < 0 || )

error();

else

{

isCorrect2 = false;

bool isCorrect3=true;

while(isCorrect3)

{

cout << "\nEnter Q3 Sales: ";

cin >> s3;

if (s3 < 0)

error();

else

{

isCorrect3= false;

bool isCorrect4=true;

while(isCorrect4)

{

cout << "\nEnter Q4 Sales: ";

cin >> s4;

if (s4 < 0)

error();

else

{

isCorrect4 = false;

ds[i].addQrtSales(s1, s2, s3, s4);

}

}

}

}

} }

}

}

}

cout << "-----------------------------------\n";

cout << "\t" << "Q1" << "\t" << "Q2" << "\t" << "Q3" << "\t" << "Q4" << endl;

cout << "-----------------------------------\n";

for (i = 0; i < 6; i++)

{

cout << "DIV" << i + 1;

for (j = 0; j < 4; j++)

{

cout << "\t" << ds[i].sales(j);

}

cout << endl;

}

cout << "-----------------------------------\n";

cout << "\nTotal All Division Sales for the Year: "

<< ds[0].getSales() << endl;

cout << endl;

system("pause");

return 0;

}

OUTPUT:

stotal.exe 1 Enter Sales Division Enter Q1 Sales: 1 Enter Q2 Sales: 1 You have entered an inualid value Press any key to contFAcprogs total.exe Enter Q1 Sales 1 Enter 2 Sales Enter 3 Sales Enter 04 Sales 1 1 1 01 Q2 Q3 04 DIU1 DIU2 DIU3 DIU4 DIUS DIU

Add a comment
Know the answer?
Add Answer to:
Have Corporate Sales for 6 divisions and their quarterly sales figures. The issue is the error...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Quarterly Sales ($ thousands) Q3 Q1 15 13 Year 1 Year 2 Q2 11 12 8...

    Quarterly Sales ($ thousands) Q3 Q1 15 13 Year 1 Year 2 Q2 11 12 8 Q4 5 6 9 What are the quarterly seasonal indices? O A. S1 = 1.30 S2 = 1.15 S3 = 0.91 S4 = 0.64 OB. 51 = 0.30 S2 = 1.15 S3 = 0.91 S4 = 1.64 C. S1 = 1.15 S2 = 0.45 S3 = 0.91 S4 = 0.64 OD. S1 = 1.40 S2 = 1.15 S3 = 1.50 S4 = 0.64

  • Quarterly Sales ($ thousands) Q1 Q3 15 Q2 11 12 Q4 5 Year 1 Year 2...

    Quarterly Sales ($ thousands) Q1 Q3 15 Q2 11 12 Q4 5 Year 1 Year 2 8 13 9 6 What are the quarterly seasonal indices? OA. S1 = 1.30 S2 = 1.15 S3 = 0.91 S4 = 0.64 OB. 51 = 0.30 S2 = 1.15 S3 = 0.91 S4 = 1.64 OC. 51 = 1.15 S2 = 0.45 S3 = 0.91 S4 = 0.64 OD. S1 = 1.40 S2 = 1.15 S3 = 1.50 S4 = 0.64

  • Rework this project to include a class. As explained in class, your project should have its...

    Rework this project to include a class. As explained in class, your project should have its functionalities moved to a class, and then create each course as an object to a class that inherits all the different functionalities of the class. You createclass function should be used as a constructor that takes in the name of the file containing the student list. (This way different objects are created with different class list files.) Here is the code I need you...

  • There is a problem with thecode. I get the error messages " 'board' was not declared...

    There is a problem with thecode. I get the error messages " 'board' was not declared in this scope", \src\TicTacToe.cpp|7|error: expected unqualified-id before ')' token| \src\TicTacToe.cpp|100|error: expected declaration before '}' token| Here is the code #ifndef TICTACTOE_H #define TICTACTOE_H #include class TicTacToe { private: char board [3][3]; public: TicTacToe () {} void printBoard(); void computerTurn(char ch); bool playerTurn (char ch); char winVerify(); }; ************************************ TicTacToe.cpp #endif // TICTACTOE_H #include "TicTacToe.h" #include #include using namespace std; TicTacToe() { for(int i =...

  • C++ Code error help. I am getting the error: "expression must have a constant value, the...

    C++ Code error help. I am getting the error: "expression must have a constant value, the value of parameter 'n' ( declared at line 7) cannot be used as a constant" I am also getting this error at lines 65 and 66 with m and n. I do not know how to fix this. Here is my code and ive marked where the errors were with lines: #include<iostream> using namespace std; // Function to allocate memory to blocks as per...

  • C++ getline errors I am getting getline is undefined error messages. I would like the variables...

    C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...

  • SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1...

    SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1 #include<iostream> using namespace std; // add function that add two numbers void add(){    int num1,num2;    cout << "Enter two numbers "<< endl;    cout << "First :";    cin >> num1;    cout << "Second :";    cin >>num2;    int result=num1+num2;    cout << "The sum of " << num1 << " and "<< num2 <<" is = "<< result;   ...

  • fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string>...

    fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str;    while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title);    getline(inFile, books[size].Author); getline(inFile, books[size].publisher);          getline(inFile,...

  • Trying to figure out how to complete my fourth case 4 (option exit), write a function...

    Trying to figure out how to complete my fourth case 4 (option exit), write a function that display a “Good Bye” message and exits/log out from user’s account displaying a menu (sign in, balance, withdraw and exit.. #include<iostream> #include <limits> using namespace std; void printstar(char ch , int n); double balance1; int main() { system("color A0"); cout<<"\n\t\t ========================================="<< endl; cout<<"\t\t || VASQUEZ ATM SERVICES ||"<< endl; cout<<"\t\t ========================================\n\n"<< endl; int password; int pincode ; cout<<" USERS \n"; cout<<" [1] -...

  • Am I getting this error because i declared 'n' as an int, and then asking it...

    Am I getting this error because i declared 'n' as an int, and then asking it to make it a double? This is the coude: #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <algorithm> #include <vector> using namespace std; void sort(double grades[], int size); char calGrade(double); int main() {    int n;    double avg, sum = 0;;    string in_file, out_file;    cout << "Please enter the name of the input file: ";    cin >> in_file;   ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT