473,498 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

5 New Member
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.  
Oct 21 '09 #1
4 11602
Banfa
9,065 Recognized Expert Moderator Expert
What about this program doesn't work?
Oct 21 '09 #2
wutang
5 New Member
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?
Oct 21 '09 #3
whodgson
542 Contributor
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!
Oct 22 '09 #4
ekassouf1
1 New Member
okay, this is what i have, i know it might too late for a post but im practicing this....


Expand|Select|Wrap|Line Numbers
  1. //Ch8AppE05.cpp
  2. //Displays the quarterly sales made 
  3. //in each of four regions, and the total 
  4. //quarterly sales for the company
  5. //Created/revised by <Elie Kassouf>
  6.  
  7. #include <iostream>
  8. #include <iomanip>
  9.  
  10. using std::cout;
  11. using std::cin;
  12. using std::endl;
  13. using std::setprecision;
  14. using std::ios;
  15.  
  16. typedef struct st_quarter
  17. {
  18.     float month_1;
  19.     float month_2;
  20.     float month_3;
  21. } QUARTERLY_SALES;
  22.  
  23. typedef struct st_region
  24. {
  25.     char name[24];
  26.     QUARTERLY_SALES quarter;
  27. } SALES_REGION;
  28.  
  29. void input_quarterly_sales_by_region( SALES_REGION* region )
  30. {
  31.     cout << "Enter sales for Month 1 in Region " << region->name << ": ";
  32.     cin >> region->quarter.month_1;
  33.  
  34.     cout << "Enter sales for Month 2 in Region " << region->name << ": ";
  35.     cin >> region->quarter.month_2;
  36.  
  37.     cout << "Enter sales for Month 3 in Region " << region->name << ": ";
  38.     cin >> region->quarter.month_3;
  39. }
  40.  
  41. void display_quarter_sales_total_by_region( const SALES_REGION* region )
  42. {
  43.     cout << setiosflags( ios::fixed | ios::showpoint ) << setprecision( 2 );
  44.     cout << "Total Quarter Sales for Region " << region->name << " = " << 
  45.         (region->quarter.month_1 + region->quarter.month_2 + region->quarter.month_3) << endl;
  46. }
  47.  
  48. void display_quarterly_sales_total_for_all_regions( const SALES_REGION* regions, const int count )
  49. {
  50.     float total = 0.0F;
  51.     for( int i = 0; i < count; i++ )
  52.     {
  53.     total += (regions[i].quarter.month_1 + regions[i].quarter.month_2 + regions[i].quarter.month_3);
  54.     }
  55.     cout << "Total Quarter Sales for All Regions: " << total << endl;
  56. }
  57.  
  58. int main()
  59. {
  60. char c;
  61. do {
  62.     SALES_REGION regions[] = { {"North", {0} },
  63.                    {"South", {0} },
  64.                    {"East", {0} },
  65.                    {"West", {0} } };
  66.  
  67.     for( int i = 0; i < (int)(sizeof( regions )/sizeof( SALES_REGION )); i++ )
  68.     {
  69.     input_quarterly_sales_by_region( &regions[i] );
  70.     }
  71.  
  72.     for( int i = 0; i < (int)(sizeof( regions )/sizeof( SALES_REGION )); i++ )
  73.     {
  74.     display_quarter_sales_total_by_region( &regions[i] );
  75.     }
  76.  
  77.     display_quarterly_sales_total_for_all_regions( regions, (int)(sizeof( regions )/sizeof( SALES_REGION )) );
  78.  
  79.     cout<<"Do you want to continue (Y/N)?">
  80.     cin>>c;
  81.     }while(c=='y'||c=='Y');
  82.  
  83.     system("pause");
  84.  
  85.  
  86.     return 0;
  87. }   //end of main function
Oct 20 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

22
3572
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html ...
0
1817
by: WindAndWaves | last post by:
Hi Gurus Here is another question that I have been struggling with for over a year. Basically, I would like to allow users to enter data into three tables in at the same time. The reason it...
7
8819
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
1
3869
by: punkybrewster | last post by:
Basically my task is to write a program that computes and displays the weekly salaries of a company's salespeople based upon information entered by the user and that also displays the total for the...
1
2366
by: nick.leggin | last post by:
I have a recordset that includes the following data Location Territory Sales Total Sales % of total sales A location can have multiple territories, and each territory has different sales
4
12411
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
43
3381
by: davidkoree | last post by:
I mean not about cookie. Does it have something to do with operating system or browser plugin? I appreciate any help.
7
2989
by: rohitsripathi | last post by:
i need help writing this program... i am in college and i do not have time do this right now as i need to study for another test....but this is due tonight...i will pay $5 if you accept to do it and...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7203
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1417
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
290
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.