Solved

Beginner programmer needs help!!!

Posted on 1998-11-25
6
241 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
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 100 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now