0

Would someone be as kind as to tell me what I got wrong for this section of my code? Thanks so much in advance!enter image description here

3 Answers 3

0

Your curly braces are supposed to enclose a function.

int main(void)
{
    // your code
}

Also, your code will not compile as it has many errors. I would recommend you checkout the videos and walkthrough videos. Also look at example codes.

0

In your code, on line 4 you have a curly brace { that should not be here. Your main function should look like this:

#include <stdio.h>
#include <cs50.h>

int main(void)
{
    // your code here
}

Keep in mind that this suggestion will only solve the problem your compiler is giving you an error. There are still some more mistakes in your code. Watch again the introductory videos of the course to understand the C syntax better.

0

Both previous answers are correct. The structure of main needs to be fixed. Additionally, look at lines 7 and 14 for syntax issues.

Line 7: this is not how to declare a variable. The part in parentheses is a test condition that would be appropriate in an if statement or a while statement. Also, that condition would never result in true. (Plug in a number and work it out, you should see why.)

Line 14: (n is invalid) -- the compiler has no way to understand what "is invlaid" means. This is pseudocode, not actual code. Pseudocode is a useful tool to help you develop programs, but must be changed into real code before you can compile.

Those are the syntax issues (unless I missed something else). Next, you will have to deal with any logic issues. For example, the last printf says "Retry", but all the program would do at that point is terminate. There's no code to have the program go back and repeat whatever you want them to retry.

You should definitely go back and review the course material and videos for the first couple of weeks to get a better understanding of how to structure a program, declaring variables, loops and decision code.

Please accept whichever answer you like to remove your question from the unanswered question pool. Let's keep up on forum maintenance. ;-)

3
  • thanks for further explanation. Commented Jul 11, 2015 at 18:01
  • I have shifted the curly brace from line 4 to line 6, but the compiler is still giving me the same response. Why is that still happening? Sorry for bothering you once again and thanks so much in advance.
    – SL824
    Commented Jul 11, 2015 at 18:04
  • because you have a seimcolon on line 5 that shouldn't be there.
    – Cliff B
    Commented Jul 11, 2015 at 18:17

You must log in to answer this question.

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