User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,745 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,499 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums

Programming Problem

Join Date: May 2007
Posts: 266
Reputation: quintoncoert is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 3
quintoncoert quintoncoert is offline Offline
Posting Whiz in Training

Re: Programming Problem

  #7  
Jul 10th, 2007
your program requirement has a lot of holes so i shall have to make some assumptions. i have to say that if my boss gives me this scanty info i go back to him and ask him to be more thorough.

i have to asume that you are not interested in printing the number of cans for each scout or the number of bonus point of each scout and therefore i also assume that you are only entering a total for a scout once.

also i am only going to give you the logic with which to flesh out the skeleton program i already gave you; a little heat might teach you not to leave your projects till the last moment again.
i am going to give you two sets of steps to get your averages and highest and after that your just need to output them using cout.

steps to get averages
1. create the following integers before the start of the the loop:
totalCans, totalBonusPoints, totalReaders.
by the way. what is a reader? is it a scout's reading? So that you have one reader for each scout? and also you do of course realise that when i say loop i mean the sentinel controlled while which checks for end.

2. inside the loop, just after receiving the number of cans, do the following:
2.1 add the cans just entered to the totalCans integer.
2.2 use either a switch or a number of if statements, the one below the other, to determine bonus points.
after that add the bonus points for that scout to the total bonus points
do it like this:
if ( cans == 300 )
totalBonusPoints = totalBonusPoints + 10;

if ( cans >= 3001 && cans <= 600 )
totalBonusPoints = totalBonusPoints + 15;

and you can figure out the last one yourself.

2.3. add one( 1 ) to the totalReaders integer. this counts each scout bringing cans.

3. this one is not an instruction. more like a note. when the program runs this logic will be executed multiple times since that is the point of looping. i used sentinel controlled looping since i thought the number of scouts was unknown in advance. if however you know how many scouts there are going to be then you can replace the sentinel controlled while with a for loop if you want. then you would also not need totalReaders since the number of scouts is known.

4. after you have exited the loop you now have totalBonusPoints as well as the totalCans. Since you also have the number of scouts you can now determine the average of bonus and cans.
int averageCans;
averageCans = totalCans / totalReaders;
do something similar for the average bonus.

///////////////////////////////////////////////////////
here are the steps to get the higest bonus and most cans.
1. before the start of the loop.
create integers highstBonus and mostCans.
initialize them both to zero.

2. now inside the loop.
test to see if the cans just received exceed the highest total of cans already received. if it does then re-assign the new highest to the most and highest integers.
like so:
if ( cans > mostCans )
mostCans = cans;

do the same for bonus after you have calculated bonus. you will have to create a new integer for bonus points to hold the bonus points while it is being compared with highestBonus.
this means that instead of adding the bonus points directly to totalBonusPoints you first place them in some integer for example holdBonus. Then after you compare holdBonus with highestBonus you decide whether to make it the new highestBonus and then you add holdBonus to totalBonusPoints.

3. you can also create another string to hold the scout name if that scout has the most cans and highest bonus. just check if his cans is more than mostCans (which you already do) and if it is you put his name in this new string. then you can print his name when you print mostCans. you have to create this string before the while loop and you compare inside the while loop.

//////////////////////////////////////////////
both above sets of steps of course happens simultaneously. i merely seperated them so you can understand easier. once your looping is done( i.e. once the sentinel controlled while ends ) you display the average number of cans, average number of bonus points as well as most cans and most bonus points.

sorry but i cant help you with visual c++. hopefully others will help you there. i myself have switched to Dev-C++ but even there things are a bit thorny.

as far as the above logic is concerned. unlike the skeleton program, i have not tested it. but i am one hundred percent sure that it is right. it might look complex if you are a beginner programmer but you must make an effort to figure it out. programming is all about logic. the above is simple. just follow the steps and use intelligence. (you own not AI! :-))
Reply With Quote  
All times are GMT -4. The time now is 7:54 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC