문제

So my task is to write a program that determines which of a company's four divisions had the greatest sales for a quarter. I am basically having an issue with the my cout statement not spitting out the location. Here is what I have: function prototypes:

double getSales(string const);
void findHighest(double, double, double, double);

main(cannot be touched instructors commands):

//variables
    double nwSales, neSales, swSales, seSales, highest; 
    string const NW = "Northwest",
                 NE = "Northeast",
                 SW = "Southwest", 
                 SE = "Southeast"; 

    cout << fixed << showpoint << setprecision(2);

    nwSales = getSales(NW); // these are calls to a function that returns a value
    neSales = getSales(NE);
    swSales = getSales(SW);
    seSales = getSales(SE); 
    findHighest(nwSales,neSales,swSales,seSales); 

function defintions:

double getSales(string const location)
{
    double sales;
    cout << "The " << location <<" branch had a quarterly sales figure of: $ ";
    cin >> sales;
    cout << "\n";
    while (sales < 0)
{
        cout << over3 << sales << " is not valid! Try again: "; 
        cin >> sales;
}
    return sales;
}

I'm pretty sure that one is right. Im having trouble with this section primarily:

void findHighest(double nwSales, double neSales, double swSales, double seSales)
{
system("CLS");
double highest  = nwSales;
string const location = "Northwest";

if (neSales > highest)
{
    highest = neSales;
    location = "Northeast";
}
if (swSales > highest)
{
    highest = swSales;
    location = "Soutwest";
}
if (seSales > highest)
{
    highest = seSales;
    location = "Southeast";
}
cout << down5;
cout << "The highest grossing division was " << location << "with $ " << highest;
cout << down7;

}

I cannot figure out why it won't tell me the location. I tried putting the cout statement in each if statement bu that messed up everything entirely. Hoping someone might be able to guide me in the right direction.

도움이 되었습니까?

해결책

Try this

string location = "Northwest";
      ^^
      no const
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top