PDA

View Full Version : Algorithm Help



BuRdTuRd5
09-30-2010, 06:00 PM
Can anyone write me an algorithm for this?

Write an algorithm that prompts the user to input a number of quarters, dimes, and nickels. The output is the total value of the coins in dollars. If the total is less that one dollar the output would be similar to $0.25.

I'm not even sure where to start

Nava2
09-30-2010, 06:09 PM
Sounds like homework..

Just write out what you want to do in psuedo code, then implement it step by step. Its pretty straight forward ;)

NCDS
09-30-2010, 06:42 PM
All that really seems necessary is a loop and a few conditional statements.

If you still are struggling with this I'll help you.

Feroc1ty
09-30-2010, 06:48 PM
#include <iostream>

using namespace std;

int main()
{
unsigned short int nickle,dime,quarter,dollars=0,cents=0;
/* creating this character due to my compiler
killing the program before being able to
view the result */
char kill;
// This program will calculate the total amount of dollars gathered from various coins.
cout << "Enter the amount of nickles :";
cin >> nickle;
cout << endl << "Enter the amount of dimes :";
cin >> dime;
cout << endl << "Enter the amount of quarters :";
cin >> quarter;
// Checks to see if there are any nickles, dimes, or quarters
while ( nickle != 0 && dime != 0 && quarter != 0 )
{
// If there are nickles, removes a nickle and adds 5 cents to the total.
if (nickle != 0)
{
nickle--;
cents+=5;
}
if (dime != 0)
{
dime--;
cents+=10;
}
if (quarter != 0)
{
quarter--;
cents+=25;
}
// If there are more than or equal to 100 cents, replaces them with a dollar.
if (cents >= 100)
{
cents-=100;
dollars++;
}
}
cout << "Total amount of dollars gathered from these coins : $" << dollars << "." << cents;
cin >> kill;
return 0;
}

g0tp0t
09-30-2010, 07:03 PM
lol, is that the second laguage setting for simba? if not then he cant use it :P

Feroc1ty
09-30-2010, 07:04 PM
Well it's in C/C++ section...