Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Beginner programmer needs help!!!

Posted on 1998-11-25
6
Medium Priority
?
250 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 85

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 Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 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.
Suggested Courses

885 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