Ok, so I've been trying to some practice programs and have come to a slight problem.
Here's the program I need to work on: Write a program that determines which of a company's four divisions (NE, SE, NW, SW) had the greatest sales for a quarter. It should include the following two functions, which are called by main.
*double getSales() is passed the name of a division. It askes the user for a division's quarterly sales figure, validates the input, then returns it. It should be called once for each division.
*void findHighest() is passed the four sales totals. It determines which is the largest and prints the name of the high grossing division, along with it's sales figure.
Here's the first code I written:
#include<iostream>
#include<iomanip>
using namespace std;
double getSales();
int main()
{
double sales;
cout << "Please enter sales for NE" << endl;
sales = getSales();
cout << "Please enter sales for SE" << endl;
sales = getSales();
cout << "Please enter sales for NW" << endl;
sales = getSales();
cout << "Please enter sales for SW" << endl;
sales = getSales();
return 0;
}
double getSales()
{
double Sales;
cin >> Sales;
return Sales;
}
Now I haven't enterted the void function yet. But is it ok if I able to use if statements in the void function?, but that might confuse it, so what is the best way to get around this problem?
I also have written it using arrays, but i don't know how to call arrays through functions. Here is the code with arrays:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
char name[4][12] = {"NE Division", "SE Division", "NW Division", "SW Division"};
double S[4];
double highest;
int high;
cout << "Please enter the quarterly sales for each division" << endl;
for (int count = 0; count < 4; count++)
{
cout << "Please enter the sales for " << name[count] << endl;
cin >> S[count];
}
highest = S[4];
for (int count = 0; count < 4; count++)
{
if (S[count] > highest)
{
high = count;
highest = S[count];
}
}
cout << "The division with the highest sales is " << name[high] << " with a total of $" << highest << endl;
return 0;
}
Thanks for any future help. I apprciate it so much.
I still have a ways to go in terms of C++.