I worked very hard on Cash and finally produced compilable code and correct output. But when I ran check50 I got these results, shown here. Please help. My code is shown below, in case you need it.
#include<cs50.h>
#include<math.h>
#include<stdio.h>
int main(void)
{
int n = 0;
do
{
n = (get_float("Change owed: ")* 200);
}
while (n < 0);
int q = ((n / 25) % 10);
int d = ((q / 10) % 10);
int r = ((d / 5) % 10);
int c = (n % 10);
int t = q + d + n + c;
int j = t * 2;
int i = j / 100;
printf("%i\n", i);
}
Update:
I edited my logic like so, shown below, based on Cliff B's answer.
#include<cs50.h>
#include<math.h>
#include<stdio.h>
int main(void)
{
int n = 0;
do
{
n = (get_float("Change owed: ") * 200);
}
while (n < 0);
int q = ((n / 25) % 10);
int d = ((q / 10) % 5);
int r = ((d / 5) % 5);
int c = (n % 5);
int t = q + d + n + c;
int j = t * 2;
int i = j / 100;
printf("%i\n", i);
}
Here are my new check50 results.
#include<cs50.h>
#include<math.h>
#include<stdio.h>
int main(void)
{
int n = 0;
do
{
n = (get_float("Change owed: ") * 200);
}
while (n < 0);
int q = ((n / 25) % 10);
int d = ((q / 10) % 5);
int r = ((d / 5) % 1);
int c = (n % 5);
int t = q + d + n + c;
int j = t * 2;
int i = j / 100;
printf("%i\n", i);
}
Update: I changed my logic but it didn't help.
#include<cs50.h>
#include<math.h>
#include<stdio.h>
int main(void)
{
int n = 0;
do
{
n = (get_float("Change owed: ") * 200);
}
while (n < 0);
int q = ((n / 25) % 10);
int d = ((q / 10) % 5);
int r = ((d / 5) % 1);
int c = (n % 1);
int t = q + d + n + c;
int j = t * 2;
int i = j / 100;
printf("%i\n", i);
}
Update: Another futile tweak.