So i need to write a program for school that displays a company's 3-month total sales for 4 different regions, North, South, West, and East. Each regions total sales for 3 months must also be displayed. I have to use this data: Region 1: 1000, 2000, 2000, Region 2: 2000, 3000, 6000, Region 3: 2000, 4000, 2000, and Region 4: 9000, 2000, 2000, Arrays cannot be used, and two for statements with one being nested must be used.
I have no idea how to do this, but i started it off like this:
//Ch8Ex4.cpp-displays a company's total sales
#include <iostream>
using std::endl;
using std::cout;
using std::cin;
int main()
{
//declare variables
int sales = 0;
int totalsales = 0;
int rsales = 0;
//get input
for (int r = 0; r < 4; r = r + 1)
{
for (int m = 0; m < 3; m = m + 1)
cout << "Enter monthly sales: ";
cin >> sales;
rsales = sales + rsales;
totalsales = totalsales + rsales;
cout << "The region's total monthly sales: " << rsales << endl;
int rsales = 0;
int sales = 0;
}
cout << "The total monthly sales is: " << totalsales << endl;
return 0;
} //end of main function
//Ch8ConEx6.cpp-displays a pattern of asterisks
#include <iostream>
using std::endl;
using std::cout;
using std::cin;
int main()
{
//declare variables
int pay = 0;
int totalpay = 0;
//get input
cout << "Enter monthly pay: ";
cin >> price;
for (int r = 1; r < 4; r = r + 1)
{
for (int m = 1; m < 3; m = m + 1);
cout << "Enter next monthly pay: ";
cin >> price;
totalprice = price + totalprice;
}
cout << "The total monthly price is: " << totalprice << endl;
return 0;
} //end of main function
First calculate the total regional sales (let the whole inner loop run,) that add it to the total sales. Do this for each region.
So you want some stuff to happen inside the outer loop, but after the inner loop (not within it.)
so the totalsales = totalsales + rsales; would go after the loop? My program doesn't even work right, it doesn't display the "Enter monthly sales" three times, it only does it once, and it then proceeds to displaying the total regional sales. Also each region is not independent of the other. So the first region will have, for example, a 2 if i enter 2. The next region will then, if i enter 2 again, display 4.
Enter monthly sales: 2
The region's total monthly sales: 2
Enter monthly sales: 2
The region's total monthly sales: 4
Enter monthly sales: 2
The region's total monthly sales: 6
Enter monthly sales: 2
The region's total monthly sales: 8
The total monthly sales is: 8
Press any key to continue . . .
Enter monthly sales: Enter monthly sales: Enter monthly sales: Enter monthly sales:
It only lets me enter on the last "Enter monthly sales". In addition to that, why do you think the 2 is adding continuously instead of separately for each region? Is there a way to fix this?