When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
42 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
What did I do wrong here?
when you did the division of cents / 100
cents did not change
you can use /= to divide and set a value
cents /= 100
that's it?
i know u just did a compound arithmetic
if you want to read more^
aka cents = cents / 100
yeah
#include <stdio.h>
int main(void)
{
int cents = 0;
printf("Number of cents\? ");
scanf("%d", ¢s);
cents /= 100;
printf("\n%d dollars and %d cents.", cents);
return 0;
}
what should i do now?
keep which before?
the code you had in the beginning
so no compound arithmetics in my code then?
#include <stdio.h>
int main(void)
{
int cents = 0;
printf("Number of cents\? ");
scanf("%d", ¢s);
int total_dollars = cents /= 100;
int total_cents = cents;
printf("\n%d dollars and %d cents.", total_dollars, total_cents);
return 0;
}
ah, i see
what should i do for total cents?
oh wait I just thought of a better way
i'm struggling to find a formula for it on google and separate the final 2 digits from dollars
and a way that works lol
have you heard of modulo operator
also known as remainder operator
%
you can get total dollar and pretend I didn't say anything
and use remainder to find the cents
yes, like 7 % 2 for example
%% prints a single % sign, so gotta avoid that
value will most likely be truncated with int, but not with float type
sorry, but your method didn't work
Anyone still able to help?
Are you trying to convert some number of cents, into the equivalent dollars and cents?
If so, you will need three variables.
The first variable will hold the total amount in cents, which you input from the user. A good name for this might be total_cents.
The second variable will the calculated dollars. A good name for this might be calculated_dollars. You can get this value by dividing total_cents by 100 and assigning the result to calculated_dollars.
The third variable will be the calculated cents. A good name for this might be calculated_cents. You can get this value by subtracting calculated_dollars * 100 from total_cents.
@flat dagger Does that make sense (not cents)? 😁
thanks, you explained it so much better than everyone else.
I struggled to find the conversion rate on Google