Greetings,

I have my first assignment for my programming class to do, but first, I will say that I am aware of those people who post entire problems requesting members to do their homework for them. This is not really what my post is about.

I'm having a little problem with getting my head around the maths part. Let me explain...

Below is the assignment in full:

A small company is writing its cheques by hand and wants to change
over to computer generated cheques.

Your boss has asked you, the new programmer, to produce a prototype
cheque writer that will accept the payees name and the amount payable
and display a cheque on the screen. The amount should be broken up
into ten thousand, thousand, hundreds and pounds. If the amount in any
of the categories is 0 then the word "zero" is put in that place.

The name of the company is MODCON Ltd.

Input the payee name: Joe
Input the amount payable: EUR 12045.67
*******************************************************
MODCON
Promises to pay Joe EUR 12045.67
1 ten_thousand
2 thousand
zero hundred
45 euro
67 cent
*******************************************************

Note that only one name is used. We cannot yet input first and
second names together.
Use only what you have learned to date Use any compiler you like to
test your code.

Try to get the cheque in the middle of the screen using <iomanip>
Identify the Inputs Outputs and constants.

Identify the data objects. Note that cheque in NOT an object as far as
we are concerned but is a collection of smaller objects that can be
seen on the screen in the example.

List the actions to be performed on those objects.

Write the algorithm consisting of the list of actions ordered
correctly and any control structures used.
Translate the algorithm into C++ code.

You need only test with positive numbers. Your code need not take
negative numbers into account.

I'm unsure how to have it display how many tens' of thousands, 'hundreads, cents etc. are in the number that was put in. Any ideas? Just some advice would be much appreciated, perhaps a link to an appropriate tutorial.

I have most of the code written. I will post it if you wish to see it....
Salutations....

OK I see nobody has responded to my topic. I have recieved an answer to the maths problem using fmod to complete the part. Apparently there is a way to do this without fmod using division and subtraction only. Any ideas???

Please respond....

Answer using fmod;

#include <iostream.h>
#include <math.h> /* You need this to use the fmod dunction */
int main()
{
double amt,amt_over;
double field_val10k,field_val1k,field_valhun,field_val10,field_val1,field_valcent;
cout << "Enter amount to be paid:"<<endl;
cin >> amt;
/*Work out the Ten thousands field */
amt_over=fmod(amt,10000);
field_val10k=(amt-amt_over)/10000;
/*Work out the thousands field */
amt_over=fmod(amt,1000);
field_val1k=((amt-amt_over)/1000)-(field_val10k*10);
/*Work out the hundreds field */
amt_over=fmod(amt,100);
field_valhun=((amt-amt_over)/100)-((field_val10k*100)+(field_val1k*10));
/*Work out the tens field */
amt_over=fmod(amt,10);
field_val10=((amt-amt_over)/10)-((field_val10k*1000)+(field_val1k*100)+(field_valhun*10));
/*Work out the single unit field */
amt_over=fmod(amt,1);
field_val1=(amt-amt_over)-((field_val10k*10000)+(field_val1k*1000)+(field_valhun*100)+(field_val10*10));
/*Cent field is the easiest!!*/
field_valcent=(fmod(amt,1)*100);

cout << "#######################################"<<endl;
cout << "Ten thousands:\t" <<field_val10k<<endl;
cout << "Thousands:\t" <<field_val1k<<endl;
cout << "Hundreds:\t" <<field_valhun<<endl;
cout << "Tens:\t\t" <<field_val10<<endl;
cout << "Ones:\t\t" <<field_val1<<endl;
cout << "Cents:\t\t"<<field_valcent<<endl;
cout << "#######################################"<<endl;

return 0;
}

If you want the number of 10,000's, say, you could do this:

float numberWithBigValueInIt = 45,678.0;

int tenThousands = (int) (numberWithBigValueInIt / 10000.0);

tenThousands would contain 4

Thanks for the reply Chainsaw, however would this way return something like '4.5678?' Whilst, what I need is '4'.

:confused:

>however would this way return something like '4.5678?'
No, integers can't hold a precision, so everything past the radix is truncated. You would have 4. But you would also have known this if you had bothered to try it before asking this question.

>however would this way return something like '4.5678?'
No, integers can't hold a precision, so everything past the radix is truncated. You would have 4. But you would also have known this if you had bothered to try it before asking this question.

I was not aware. I didn't try it becuase I didn't think it would work.

Now that I've tried it, I can't seem to actually get it working....This is what I have come up with so far but I cannot determine what's wrong with it. Can someone see anything wrong with it?

#include<iostream>
#include<iomanip>
#include<string>


using namespace std;

int main()
{

string name;
double amount;
string prompt;
prompt = "Input payee name here like: ";
cout << prompt;
cin >> name;
cin.get();

prompt = "Input amount payable: ";
cout << prompt;
cin >> amount;
cin.get();

int ten_thousand;
int thousand;
int hundread;
int euro;
double cent;

cout << endl;
cout << endl;

// THE CHEQUE
cout << "*******************************************";
cout << endl << "\t"<< setw(20) << "MODCON" << endl;

cout << "Promises to pay " << "\t" << name << setw(20) << "EUR" << amount <<endl;

//Calculate amount of thousands.
int thousand = (int) (amount / 1000);
cout << "Thousands " << setw(20) << thousand;

cout << endl << "**********************************************";

cin.get();

return 0;
}

Update** I have got it to give me the amount of ten_thousands and thousands. The next one seems a bit tricky.

e.g.... lets say the amount is 35857.56

ten_thousand = (int) (amount / 10000);
ten_thousand comes up as 3.

thousand = (int) (amount / 1000) - (ten_thousand * 10);
thousand comes up as 5

However it's the next part I cannot seem to get, the 'hundread'...

>I didn't try it becuase I didn't think it would work.
Serves you right then.

>I can't seem to actually get it working
It could be something to do with your defining the name thousand twice.

I have got it working. All of it! Fantastic! :mrgreen:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.