0

I recently started CS50 and I am currently in the process of completing Problem Set 1 - Mario (The less comfortable one). I am really confused by the hash pyramid problem, so I've been trying different things. I decided to try the code given to print a square in the hint, so I put it into the lab.

1 #include <stdio.h>
2 #include <cs50.h>
3 
4 // Variables
5 int height;
6 int hash;
7 int space;
8 int i;
9 int n;
10
11 int main(void);
12 {
13    // Asks user for integer between 1 and 8, inclusive, and prints pyramid based on user input
14    int i = get_int("Height: \n");
15  int n;
16  do 
17    {
18        for (int height = 0; i < n; height++)
19        {
20            for (int space = 0; space < n; space++)
21            {
22                printf("#");
23            }
24            printf("\n");
25        }
26    }
27    while (i > 8 || i <= 0);
28 }

When I try to compile this, I get only one error that says 'Expected identifier or '('' (in line 12, character 1). I am absolutely clueless on what this means, can anyone help me with this please? I am going to try and write my own code for the pyramid, but I wanted to try the square first to get a basic idea. I might be back for help with the pyramid though :p

Thanks!

1 Answer 1

0
11 int main(void);
12 {

Hmmm.... See that semicolon? Take it out. It is telling the compiler that line 11 is a function signature line, not the actual start of main.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

2
  • Oh, thank you! I am really inexperienced with code and I’ve just started, so I didn’t notice that. Thanks once again!
    – AK-25
    Commented Apr 7, 2019 at 16:49
  • No problem. It's a very common newbie mistake. I did it too when I was learning!
    – Cliff B
    Commented Apr 8, 2019 at 2:01

You must log in to answer this question.

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