1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
3
Rep Power
0

#### Separate number

Hello guys,
I would like to separate a float number for my project.
The project says: The user gives you for example number 1200,20euro. Create a program that separate the number and sawing to the user how many 500, 200, 100 .... 0.20, 0.10,.... the number will have.
1200,20 should show: 2*500, 1*200,1*0.20
i am beginner so the program has to be simple (not if, while, case etc)
2. Separate the input and output from computation.

Input: What is acceptable? Define this so we can understand how to convert it to useful numbers.
1200,20euro
could be quite different from
1200.20
Is the posix locale defined?

How does the program respond to bad information?

Computation:
Please explain the method you'd use to solve this problem. Perhaps solve a few problems on paper.

What information do you need?

Please write that information in c.

Output: The output for valid input looks well defined. What data structures would be appropriate to show it?
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
101
Rep Power
0
" am beginner so the program has to be simple (not if, while, case etc)"

I don't want to ruin your day but learning those data structures are the basics of C.

On top of that I'm confused what you want. Sorry
4. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Mar 2013
Posts
3
Rep Power
0
First of all saying that i am a beginner i mean that i am now learning c and my professor going step by step. We have just ended / and %. So he gave as a project (the one that i mentioned in my first post).
I asked a classmate and he said it would be better if i separate the float number (1220.20) in 2 integer (1200 and 20) or something like that.
I have prepared something :
#include <stdio.h>
main()
{
/* fivehun is the five hundred paper money */
int euro,fivehun,twohun;
printf("Give a number");
scanf("%d",&euro);
fivehun= euro/500;
euro=euro%500;
printf("The number you gave has %d of 500 paper money\n",fivehun);
twohun= euro/200;
euro=euro%200;
printf("The number you gave has %d of 200 paper money\n",twohun);
getch();
/* its easy to continue like this with 100euro,50euro .....2 euro, 1euro
but the problem is if the user give you a float number like 1200,30. That's my problem*/

1234,56

into 1234 and 56---different from your splitting.

Thus read the value as a float:

float euro;
int whole, change;
scanf("%f",&euro);

whole = (int)euro;
change = (int)(0.5+ 100 * (euro - whole));

euro-whole is the fractional part.
multiply by 100 assuming the change is decimal with smallest unit being 1% of 1 euro.
Adding one half followed by conversion to int should give you the change as an integer.