Solved

Beginner programmer needs help!!!

Posted on 1998-11-25
6
247 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
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!

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

617 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