0
#include <cs50.h>
#include<math.h>
int main(void)
{
    do
        {
        int f = round(get_float("Change owed: ") * 100);
        }
    while (f < 0)
        q = ((f / 25)%)
        d = ((q / 10)%)
        n = ((d / 5)%)
        c = (n%)
        i = q + d + n + c
    printf ("%i");
}

Can anyone please tell me how to fix my code? Thank you for your time and help!

ErrorHelp50

As for variable f, isn't f declared in Cash 7:12?

Edit: I edited the code to declare the variables, a la below.

#include <cs50.h>
#include<math.h>
int main(void)
{
    do
        {
        int f = round(get_float("Change owed: ") * 100);
        }
    while (f < 0)
        int q = ((f / 25)%)
        int d = ((q / 10)%)
        int n = ((d / 5)%)
        int c = (n%)
        int i = q + d + n + c
    printf ("%i");
}

Yet I still get this: error2help50 2

Update: I fixed my code, as shown below, but nothing helped.

#include <cs50.h>
#include<math.h>
int main(void)
{
    do
    {
        int f = round(get_float("Change owed: ") * 100);
    }
    while (f < 0)
        int q = ((f / 25) %)
                int d = ((q / 10) %)
                        int n = ((d / 5) %)
                                int c = (n %)
                                        int i = q + d + n + c
                                                printf("%i");
}

Update: The new semicolon didn't help.

#include <cs50.h>
#include<math.h>
int main(void)
{
    do
    {
        int f = round(get_float("Change owed: ") * 100);
    }
    while (f < 0);
        int q = ((f / 25) %)
                int d = ((q / 10) %)
                        int n = ((d / 5) %)
                                int c = (n %)
                                        int i = q + d + n + c
                                                printf("%i");
}

2 Answers 2

0

Have a look at the syntax for a do while loop (The CS50 Style guide has a section on that) You might spot what you're missing that then causes the later clang errors.

4
  • I did as the instructions said, but unfortunately it didn't help. See the above update. @curiouskiwi Commented May 27, 2020 at 3:59
  • You are still missing the required punctuation after your while statement.
    – curiouskiwi
    Commented May 27, 2020 at 4:04
  • AH! THE SEMICOLON! I MUST FIX THAT!!!! Commented May 27, 2020 at 4:06
  • Sadly adding the semicolon did not help. @curiouskiwi Commented May 27, 2020 at 4:16
0

I figured it out! By looking at one of my previous psets I added a declaration on top.

DISCLAIMER: THIS CODE STILL HAS OTHER ERRORS.

#include <cs50.h>
#include<math.h>
int main(void)
{
    int n = 0;
    do
    {
     n = (get_float("Change owed: ") * 100);
    }
    while (n < 0);
        int q = ((n / 25) %)
                int d = ((q / 10) %)
                        int i = ((d / 5) %)
                                int c = (n %)
                                        int i = q + d + n + c
                                                printf("%i");
}

Notice the int n = 0? Just like that I eliminated the top two errors in my screenshot. I killed two birds with one stone!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .