How would I create a program that that displays the sum of a sales amount in each of 4 regions, during a 3 month period, which would also display the sum? …Nothing fancy. I am a beginner and want to be able to understand the code…Pls…
I need to loop it …this is what I have but I am terrible wrong I am sure. There has to be a way off not adding all the regions? I commented out some of the region.
include %26lt;iostream%26gt;
using std::cout;
using std::cin;
using std::endl;
int main()
{ double sales = 0.0;
double totalSales = 0.0;
int region = 0;
const int Nregion = 1;
const int Sregion = 2;
const int Eregion = 3;
const int Wregion = 4;
while (region %26lt; 4)
{
cout%26lt;%26lt; "Enter first sale amount for North region " %26lt;%26lt; Nregion %26lt;%26lt; " : " ;
cin %26gt;%26gt; sales;
//cout%26lt;%26lt; "Enter first sale amount for South region " %26lt;%26lt; Sregion %26lt;%26lt; " : " ;
//cin %26gt;%26gt; sales;
{
totalSales = totalSales + sales;
// cout%26lt;%26lt; "Enter next sale amount region " %26lt;%26lt; region %26lt;%26lt; " :" ;
//cin %26gt;%26gt; sales;
}
cout %26lt;%26lt; "Region" %26lt;%26lt; region %26lt;%26lt; "sales: "
%26lt;%26lt; totalSales %26lt;%26lt; endl;
region = region + 1;
totalSales = 0.0;
Return 0;
}
...................c++?
Try to understand logic and problem solving using programming languages and then object oriented concept. Then it comes to C++. By the way , i have sited (good approach) an example for your problem :-
#include %26lt;iostream%26gt;
#include %26lt;string%26gt;
using namespace std;
class regions{
string regionName;
int sale;
public:
regions(){}
public:
void setRegionName(string rname){
regionName = rname;
}
void setRegionSale(int s){
sale = s;
}
void showRegionInfo(){
cout%26lt;%26lt;"\n Region Name :"%26lt;%26lt;regionName%26lt;%26lt;" ; \n "%26lt;%26lt; "Sale : "%26lt;%26lt;sale%26lt;%26lt;"\n";
}
string getName(){
return regionName;
}
int getSale(){
return sale;
}
regions operator+(regions r){
regions r1;
r1.setRegionName(regionName + ", " + r.getName());
r1.setRegionSale(sale + r.getSale());
return r1;
}
};
int main() {
regions n,s,e,w;
n.setRegionName("North Reg");
s.setRegionName("South Reg");
e.setRegionName("East Reg");
w.setRegionName("West Reg");
n.setRegionSale(1000);
s.setRegionSale(1400);
e.setRegionSale(1100);
w.setRegionSale(1200);
regions combinedRegion = n+e+s+w;
combinedRegion.showRegionInfo();
return 0;
}
Reply:were you taught about structures / multi dimensional arrays ;-)
thats a hint...
I'm not gonna do ya homework for ya.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment