Free AdviceGet Free Advice
Home | Get advice | Give advice | Topics | Columnists | - !START HERE! -
Make Suggestions | Sitemap

Get Advice


Search Questions

Ask A Question

Browse Advice Columnists

Search Advice Columnists

Chat Room

Give Advice

View Questions
Search Questions
Advice Topics

Login

Username:
Password:
Remember me
Register for free!
Lost Password?

Want to give Advice?

Sign Up Now
(It's FREE!)

Miscellaneous

Shirts and Stuff
Page Backgrounds
Make Suggestions
Site News
Link To Us
About Us
Terms of Service
Help/FAQ
Sitemap
Contact Us


Algorithms?


Question Posted Thursday December 3 2009, 5:34 pm

I have been confused on how to write algorithms from day one! I am currently taking an online class and am so lost with this topic. We have an assignment due in a week where we have to write an algorithm for a certain problem and then create a program for it. Here are my problems:
1. Write a program to calculate the change in quarters, dimes, nickels, and pennies when any amount from 1 to 99 is entered. The program should return the minimum coins that represent the amount entered. For example 37 cents should yield one quarter, 1 dime, and two pennies.
2. Write a program to find the smallest number, the largest number, and the average of any five numbers entered by the user. For example, if the five numbers entered are 1, 2, 3, 4, and 5, the answers should be smallest =1, largest=2, and average=3. (Your program should handle any numbers from 1 to 1,000)

So far what I have for the first one is:
cin>>inputCoins
while(inputCoins > 0)
{
if(inputCoins >= 25)
Quarters ++
inputCoins -= 25
elseif(inputCoins >= 10)
Dimes ++
inputCoins -= 10
elseif(inputCoins >=5)
Nickles ++
inputCoins -= 5
elseif(inputCoins >=1)
Pennies ++
inputCoins -= 1
}
cout>> //print your coin totals out here.

Any tips? any help? SO CONFUSED!!!


[ Answer this question ]
Want to answer more questions in the Work & School category?
Maybe give some free advice about: School?


NinjaNeer answered Saturday December 5 2009, 12:35 pm:
Something I find helps when troubleshooting is going through verbally and putting actual words to the program.

Right now, if the amount is higher than 25, the number of quarters goes up by one, and the amount is decreased by 25, the value of a quarter. So far, so good.

Now you move on to dimes. You say that if it's higher than or equal to 10, you up the number of dimes, and then decrease the amount by 10. Here's where I think an issue may be. Would you not need to say where the amount is greater than 10, but less than 25?

For instance: you enter 26.

For this, Quarters++, but ALSO, Dimes++ because it is greater than 10 as well as greater than 26.

For problem #2, I'm rusty on my C++ (it's been a few years). I believe what you would do is to assign each user-entered value to a variable as it is entered. You then need to check each variable to make sure it fits the parameters (i.e. has the person entered all five, is it between 1-1000). Now, just work bit by bit.

To find out which number is the smallest, create a variable called "Smallest". If variable 1 < variable 2 AND variable 1 < variable 3, etc, then Smallest = Variable 1. The opposite works for the largest.

As for the average, variable 1 + variable 2 + variable 3 + variable 4 + variable 5 divided by 5 will give you the solution.

Other than that, it's all the printouts and stuff you have to worry about.

[ NinjaNeer's advice column | Ask NinjaNeer A Question
]


More Questions:

<<< Previous Question: Dream Interpretation
Next Question >>> dry eyes

Recent popular questions:
Want to give advice?

Click here to start your own advice column!

What happened here with my gamer friends?

All content on this page posted by members of advicenators.com is the responsibility those individual members. Other content © 2003-2014 advicenators.com. We do not promise accuracy, completeness, or usefulness of any advice and are not responsible for content.

Attention: NOTHING on this site may be reproduced in any fashion whatsoever without explicit consent (in writing) of the owner of said material, unless otherwise stated on the page where the content originated. Search engines are free to index and cache our content.
Users who post their account names or personal information in their questions have no expectation of privacy beyond that point for anything they disclose. Questions are otherwise considered anonymous to the general public.

[Valid RSS] eXTReMe Tracker