Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Beginner programmer needs help!!!

Posted on 1998-11-25
6
Medium Priority
?
249 Views
Last Modified: 2010-04-01
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
Comment
Question by:furley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1178656
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
 
LVL 84

Expert Comment

by:ozo
ID: 1178657
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
 

Author Comment

by:furley
ID: 1178658
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 6

Expert Comment

by:thresher_shark
ID: 1178659
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
 

Accepted Solution

by:
Bookface earned 300 total points
ID: 1178660
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
 
LVL 11

Expert Comment

by:alexo
ID: 1178661
>> 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

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question