GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-Apr-2006, 01:04
Mrsnap32 Mrsnap32 is offline
New Member
 
Join Date: Mar 2006
Posts: 5
Mrsnap32 is on a distinguished road

Having trouble with body of programs


I am having alot of trouble with the main body of programs. On my homework assingment it says to 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 also should display the total sales made during the three months. Complete the program by entering 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 regions total sales for the three month period, and the companys total sales for the three month period. I will be using microsoft visual studio 2003.net. Any help anyone can give me would greatly appreciated. David

CPP / C++ / C Code:
//Ch8AppE04.cpp – displays the quarterly sales made 
//in each of four regions and the total quarterly sales for the company
//Created/revised by <your name> on <current date>

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
	
	
	return 0;
}   //end of main function
Last edited by LuciWiz : 05-Apr-2006 at 01:43. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #2  
Old 05-Apr-2006, 02:48
Guidelines Plz Guidelines Plz is offline
Junior Member
 
Join Date: Sep 2005
Posts: 87
Guidelines Plz is on a distinguished road

Re: Having trouble with body of programs


This is the third time you've been asked to use code tags. Is there something about the Guidelines you don't understand? You can ask questions about them too...
__________________

Please read http://www.gidforums.com/t-5566.html. They were written to help you create a request that is readable and has enough information we can actually tell what you need help with.
  #3  
Old 05-Apr-2006, 08:08
davis
 
Posts: n/a

Re: Having trouble with body of programs


Quote:
Originally Posted by Mrsnap32
I am having alot of trouble with the main body of programs. On my homework assingment it says to 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 also should display the total sales made during the three months. Complete the program by entering 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 regions total sales for the three month period, and the companys total sales for the three month period. I will be using microsoft visual studio 2003.net. Any help anyone can give me would greatly appreciated. David


CPP / C++ / C Code:
#include <iostream>
#include <iomanip>

using std::cout;
using std::cin;
using std::endl;
using std::setprecision;
using std::ios;

typedef struct st_quarter
{
    float month_1;
    float month_2;
    float month_3;
} QUARTERLY_SALES;

typedef struct st_region
{
    char name[24];
    QUARTERLY_SALES quarter;
} SALES_REGION;

void input_quarterly_sales_by_region( SALES_REGION* region )
{
    cout << "Enter sales for Month 1 in Region " << region->name << " ";
    cin >> region->quarter.month_1;

    cout << "Enter sales for Month 2 in Region " << region->name << " ";
    cin >> region->quarter.month_2;

    cout << "Enter sales for Month 3 in Region " << region->name << " ";
    cin >> region->quarter.month_3;
}

void display_quarter_sales_total_by_region( const SALES_REGION* region )
{
    cout << setiosflags( ios::fixed | ios::showpoint ) << setprecision( 2 );
    cout << "Total Quarter Sales for Region " << region->name << " = " << 
	    (region->quarter.month_1 + region->quarter.month_2 + region->quarter.month_3) << endl;
}

void display_quarterly_sales_total_for_all_regions( const SALES_REGION* regions, const int count )
{
    float total = 0.0F;
    for( int i = 0; i < count; i++ )
    {
	total += (regions[i].quarter.month_1 + regions[i].quarter.month_2 + regions[i].quarter.month_3);
    }
    cout << "Total Quarter Sales for All Regions: " << total << endl;
}

int main()
{
    SALES_REGION regions[] = { {"North", {0} },
			       {"South", {0} },
			       {"East", {0} },
			       {"West", {0} } };

    for( int i = 0; i < (int)(sizeof( regions )/sizeof( SALES_REGION )); i++ )
    {
	input_quarterly_sales_by_region( &regions[i] );
    }

    for( int i = 0; i < (int)(sizeof( regions )/sizeof( SALES_REGION )); i++ )
    {
	display_quarter_sales_total_by_region( &regions[i] );
    }

    display_quarterly_sales_total_for_all_regions( regions, (int)(sizeof( regions )/sizeof( SALES_REGION )) );


    return 0;
}


Output:
Code:
Enter sales for Month 1 in Region North 12.34 Enter sales for Month 2 in Region North 12.34 Enter sales for Month 3 in Region North 12.34 Enter sales for Month 1 in Region South 10.10 Enter sales for Month 2 in Region South 10.10 Enter sales for Month 3 in Region South 10.10 Enter sales for Month 1 in Region East 40.40 Enter sales for Month 2 in Region East 40.40 Enter sales for Month 3 in Region East 40.40 Enter sales for Month 1 in Region West 1 Enter sales for Month 2 in Region West 2 Enter sales for Month 3 in Region West 3 Total Quarter Sales for Region North = 37.02 Total Quarter Sales for Region South = 30.30 Total Quarter Sales for Region East = 121.20 Total Quarter Sales for Region West = 6.00 Total Quarter Sales for All Regions: 194.52

Next time you're going to have to actually have some code in your post or I'm not responding...unless the question is particularly interesting. This code took me about 10 minutes to write. I'd think that you can spend 10 minutes on it yourself before posting.


:davis:
 
 

Recent GIDBlogUS Elections and the ?Voter?s Responsibility? by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help with simple C programs... Whats wrong? ovadoggvo C Programming Language 4 19-May-2005 08:15
1 line php cover function changes result of called programs schgid MySQL / PHP Forum 0 03-May-2005 11:15
help in c programs kitin21 C Programming Language 4 08-Sep-2004 08:38
Having trouble trying to format C: Nickster64 Computer Software Forum - Windows 2 27-Jul-2004 08:31

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:32.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.