• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

Beginner programmer needs help!!!

I have 2 questions:

1. How do I create a program that reads 2 digits up to 30 digits each, add these integers together, and display the result.

2. How do I write a program that computes the minimum number of coins and bills needed to make change for a purchase? The program will read in an input file that contains 2 numbers, the cost and the tendered amount. It will then calculate the change needed. For example, if the cost is $10.50 and the tendered amount is $20.00, the change will be 1 $5 bill, 4 $1 bills, and 2 quarters.

I'm not expecting code (although that won't hurt). I just need an idea of how to do these problems. Maybe even some pseudo code. Thanks.
0
furley
Asked:
furley
1 Solution
 
thresher_sharkCommented:
For the first one, you'll need a long integer class.  There are many of these on the internet.  Go to a search engine and type something like "long integer class c++ source code download here"

Is this for homework or something?
0
 
ozoCommented:
What country are you in?
Won't the minimum number of coins and bills needed to make change for a purchace of $10.50 with $20.00 tendered be 1 $5 bill, 2 $2 bills, and 1 50ยข coin?
0
 
furleyAuthor Commented:
yeah, this is for homework.

For the first question, how would I do it without using classes?

I'm in Canada. The bills and coins used are $10, $5, $1, 25 cents (quarter), 10 cents (dime), 5 cents (nickel), and 1 cent (penny).
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
thresher_sharkCommented:
Hehe, you have to be kidding, you want to be able to add integers of that length WITHOUT classes?  Ugh, your program is going to be rather messy when it gets done that's all I have to say.

Here is a tip.  The integers should be represented using strings.  Then, to add them, think of how you do it with pencil and paper.  You add them together by adding each pair of digits and carrying if necessary.
0
 
BookfaceCommented:
Using strings to do addition doesn't have to be messy:

1. First, define two strings (simply a array of characters: i.e.
char num1[31];
)

2. Get the user input from cin into the first string.
cin >> string_identifer;

3. All the characters should be numerical digits in ASCII form. You can error-check this if you wish with a for loop preforming the isdigit function on each character:
for(i=0;i<=strlen(string_identifier);i++)
   if (!isdigit(string_identifier[i])) return 1;

4. Continue from i to 30, replacing whatever may be there with the character '0'.

5. Subtract the value of '0', using the same type of for loop.

6. Repeat 2-5 for the second string.

7. Again cycle through the thirty digits, this time adding the value of the second to the value of the first.

8. Go through again, looking for values over 10. Use division by 10, stored into an int; the two 'characters' in the strings will be cast as ints, and only the carry digit will be stored into the temp int. Now mod them to get an answer to store in your final output string.

9. Once you have a final string containing no characters with values greater than ten, you can add '0' (or 48 if you like, the ASCII value of 0) to the integers in order to get string you can print.

You can actually put all this into one for loop, but I wouldn't advise it unless you really think you know what you're doing.

As for your second question, you would probably be best off doing something like this:
input: 10.50 20.00
 
int twentys,tens,fives,ones,c25,c10,c5;
twentys=tens=fives=ones=c25=c10=c5;
double cost = 10.50; // assuming these are the values read
double tendered = 20.00;
double change = tendered-cost; //=20.00-10.50
.
while(change>=10)
{
tens++;
change-=10;
}
.

Of course, there would be a limit of accuracy, whether you stopped at $20, $100, etc. bills, unless you do each form of bill and coin seperately.
0
 
alexoCommented:
>> For the first question, how would I do it without using classes?
furley, your question was posted in the C++ area.  C++ is all about classes, they are the only reason for C++'s existence.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now