Connecting Tech Pros Worldwide Forums | Help | Site Map

How do I create a C++ program displaying total sales made during the three months?

Newbie
 
Join Date: Oct 2009
Posts: 4
#1: Oct 21 '09
Create a program that displays the sum of the sales amounts made in each of four regions (North, South, East, West) during a three month period. The program should display the total sales made during the three months.
1. Complete the program by entering the C++ code that allows the user to enter four sets(one set for each region) of three sales amounts (one sales amount for each month). The program should display each region's total sales for the 3-month period, and the company's total sales for the 3-month period.
-You must use some type of loop to receive credit for the exercise....cannot use arrays

What I have so far.....
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using std::cout;
  3. using std::cin;
  4. using std::endl;
  5.  
  6.  
  7. int main()
  8. {
  9. //declare variables
  10. char region = ' ';
  11. int monthlySales1 = 0;
  12. int monthlySales2 = 0;
  13. int monthlySales3 = 0;
  14. int totalSales = 0;
  15. int totalRegSales = 0;
  16.  
  17. cout << "Enter region (N/S/E/W): ";
  18. cin >> region;
  19.  
  20. do
  21. {
  22. // Get Monthly sales...
  23. cout << "First monthly sales amount for Region " << region << ": ";
  24. cin >> monthlySales1;
  25.  
  26. cout << "Next monthly sales amount for Region " << region << ": ";
  27. cin >> monthlySales2;
  28.  
  29. cout << "Next monthly sales amount for Region " << region << ": ";
  30. cin >> monthlySales3;
  31.  
  32. // Add our regional sales
  33. totalRegSales = monthlySales1 + monthlySales2 + monthlySales3;
  34.  
  35. // Display the sales made for that region....
  36. cout << "Total sales for Region " << region << ": " << totalRegSales << "\n\n";
  37.  
  38. totalSales += totalRegSales;
  39.  
  40. // And if our total sales is more than 0, then display it before
  41. // asking for our next region.
  42. if( totalSales > 0 ){
  43. cout << "\nTotal Sales at this point: " << totalSales << "\n\n";
  44. }
  45.  
  46. cout << "Enter region (N/S/E/W): ";
  47. cin >> region;
  48. }
  49. while (region == 'N' || region == 'S' || region == 'E' || region == 'W');
  50. return 0;
  51. }
  52.  

Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,206
#2: Oct 21 '09

re: How do I create a C++ program displaying total sales made during the three months?


What about this program doesn't work?
Newbie
 
Join Date: Oct 2009
Posts: 4
#3: Oct 21 '09

re: How do I create a C++ program displaying total sales made during the three months?


ok here I go.
1. I can't seem to get a " Invalid entry" code if I enter say ' T ' instead of ' N' , ' S ', ' E', or ' W '.

2. I also added region = toupper(region) in order to make the letter of region capitalized. When it asks for a another region, I enter lower case ' w ' but it does not let me keep adding information. It will if I enter a capital ' W '.

3. Also im not sure how to make it stop after I enter the fourth region.



sorry and thanks. I'm a Noob when it comes to C++ still. Is there a better way to do this than what I have?
Familiar Sight
 
Join Date: Jan 2007
Posts: 193
#4: Oct 22 '09

re: How do I create a C++ program displaying total sales made during the three months?


Think you are on the right track.
Concentrate on getting the N region to print the correct result. Then add the code for the next region and so on.
Two loops would appear practical with the first loop controlling region and the second nested one controlling sales total. Maybe with 2 loops you will get double marks!
Reply


Similar C / C++ bytes