need help trying compile the program but getting this error on line 107 expect \
ID: 3799740 • Letter: N
Question
need help trying compile the program but getting this error on line 107 expect '}' at the end of input.
Write a program that determines which of a company's eight divisions (North, South, East, West, Northeast, Southeast, Northwest, Southwest) had the greatest sales for a quarter. It should include the following two functions which are called only by main.
double getSales() - it is passed the name of a division. It asks the user for a division's quarterly sales figure, validates the input then returns it. It should be called once for each division. Negative dollar amounts are invalid.
void findHighest() - it is passed the eight sales amounts. It then determines which is the largest and prints the name of the high grossing division along with it's sales figure.
#include <iostream>
#include <iomanip>
#include <cstdlib>
double getSales();
void findHighest(double, double, double, double, double, double , double, double);
int main()
{
double North, South, East, West, Northeast, Southeast, Northwest, Southwest;
std::cout << "Enter the quarterly sales for North Division: " << std::endl;
North = getSales();
std::cout << "Enter the quarterly sales for South Division: " << std::endl;
South = getSales();
std::cout << "Enter the quarterly sales for East Division: " << std::endl;
East = getSales();
std::cout << "Enter the quarterly sales for West Division: " << std::endl;
West = getSales();
std::cout << "Enter the quarterly sales for Northeast Division: " << std::endl;
Northeast = getSales();
std::cout << "Enter the quarterly sales for Southeast Division: " << std::endl;
Southeast = getSales();
std::cout << "Enter the quarterly sales for Northwest Division: " << std::endl;
Northwest = getSales();
std::cout << "Enter the quarterly sales for Southwest Division: " << std::endl;
Southwest = getSales();
findHighest(North, South, East, West, Northeast, Southeast, Northwest, Southwest);
return 0;
}
double getSales()
{
double sales;
std::cin >> sales;
if(sales < 0)
{
std::cout << " Error: Invalid figures please enter above zero" << std::endl;
exit(0);
}
return sales;
}
void findHighest(double North,double South,double East,double West, double Northeast,double Southeast,double Northwest,double Southwest)
{
if (East > West && North > South)
{
if(North > South)
{
std::cout << "The North division had the greatest number of sales, $";
std::cout << North << std::endl;
}
if (North > South && West > East)
{
if(West > East)
{
std::cout << "The West division had the greatest number of sales, $";
std::cout << West << std::endl;
}
if (North > South && East > West)
{
if(East > West)
{
std::cout << "The East division had the greatest number of sales, $";
std::cout << East << std::endl;
}
if (East > West && South > North )
{
if(South > North)
{
std::cout << "The South division had the greatest number of sales, $";
std::cout << South << std::endl;
}
if (Northeast > Southeast && Northeast > Northwest)
{
if(Northeast > Southwest)
{
std::cout << "The Northeast division had the greatest number of sales, $";
std::cout << Northeast << std::endl;
}
}
if (Southeast > Northeast && Southeast > Northwest)
{
if(Southeast > Southwest)
{
std::cout << "The Southeast division had the greatest number of sales, $";
std::cout << Southeast << std::endl;
}
}
if (Northwest > Northeast && Northwest > Southeast)
{
if(Northwest > Southwest)
{
std::cout << "The Northwest division had the greatest number of sales, $";
std::cout << Northwest << std::endl;
}
}
if (Southwest > Northeast && Southwest > Southeast)
{
if(Southwest > Northwest)
{
std::cout << "The Southwest division had the greatest number of sales, $";
std::cout << Southwest << std::endl;
exit (0);}
Explanation / Answer
I have checked about the error and modified it. The ending bracket was not done properly remaining everything is right.I have written the modified code below (only compilation error is removed ) i.e just added extra braces so that the function gets completed.
Code:
#include <iostream>
#include <iomanip>
#include <cstdlib>
double getSales();
void findHighest(double, double, double, double, double, double , double, double);
int main()
{
double North, South, East, West, Northeast, Southeast, Northwest, Southwest;
std::cout << "Enter the quarterly sales for North Division: " << std::endl;
North = getSales();
std::cout << "Enter the quarterly sales for South Division: " << std::endl;
South = getSales();
std::cout << "Enter the quarterly sales for East Division: " << std::endl;
East = getSales();
std::cout << "Enter the quarterly sales for West Division: " << std::endl;
West = getSales();
std::cout << "Enter the quarterly sales for Northeast Division: " << std::endl;
Northeast = getSales();
std::cout << "Enter the quarterly sales for Southeast Division: " << std::endl;
Southeast = getSales();
std::cout << "Enter the quarterly sales for Northwest Division: " << std::endl;
Northwest = getSales();
std::cout << "Enter the quarterly sales for Southwest Division: " << std::endl;
Southwest = getSales();
findHighest(North, South, East, West, Northeast, Southeast, Northwest, Southwest);
return 0;
}
double getSales()
{
double sales;
std::cin >> sales;
if(sales < 0)
{
std::cout << " Error: Invalid figures please enter above zero" << std::endl;
exit(0);
}
return sales;
}
void findHighest(double North,double South,double East,double West, double Northeast,double Southeast,double Northwest,double Southwest)
{
if (East > West && North > South)
{
if(North > South)
{
std::cout << "The North division had the greatest number of sales, $";
std::cout << North << std::endl;
}
if (North > South && West > East)
{
if(West > East)
{
std::cout << "The West division had the greatest number of sales, $";
std::cout << West << std::endl;
}
if (North > South && East > West)
{
if(East > West)
{
std::cout << "The East division had the greatest number of sales, $";
std::cout << East << std::endl;
}
if (East > West && South > North )
{
if(South > North)
{
std::cout << "The South division had the greatest number of sales, $";
std::cout << South << std::endl;
}
if (Northeast > Southeast && Northeast > Northwest)
{
if(Northeast > Southwest)
{
std::cout << "The Northeast division had the greatest number of sales, $";
std::cout << Northeast << std::endl;
}
}
if (Southeast > Northeast && Southeast > Northwest)
{
if(Southeast > Southwest)
{
std::cout << "The Southeast division had the greatest number of sales, $";
std::cout << Southeast << std::endl;
}
}
if (Northwest > Northeast && Northwest > Southeast)
{
if(Northwest > Southwest)
{
std::cout << "The Northwest division had the greatest number of sales, $";
std::cout << Northwest << std::endl;
}
}
if (Southwest > Northeast && Southwest > Southeast)
{
if(Southwest > Northwest)
{
std::cout << "The Southwest division had the greatest number of sales, $";
std::cout << Southwest << std::endl;
exit (0);}
}
}
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.