Hot answers tagged

17 votes
Accepted

Error: "make: *** No rule to make target `mario'. Stop."

This is a very common question asked by new students. The make command is used to compile the source code and generate an executable program. While there are complexities to this process (more ...
user avatar
  • 63.5k
12 votes

What's wrong with my code for mario?

Five months is too long for a problem like mario or pretty much any other problem in the course. You could try solving it manually with low-tech tools (e.g., a pencil and a paper) trying to draw half ...
user avatar
  • 17.4k
8 votes
Accepted

Problem with "expression result unused" error in for-loop

In a for loop, the first item is the initialization. You are saying for (height; height>0; height--) and the compiler is expecting that first item to be an initialization but you have simply ...
user avatar
  • 18.4k
7 votes
Accepted

Stuck on pyramid for mario.c

I can not seem to make a pyramid, only a straight line of #'s. In order to make a pyramid, you'll need more than one line. The way to move to the next line when printing out characters to the ...
user avatar
  • 2,136
6 votes

Completely lost.. pset1, Mario help

You are validating the input after they enter it. So your program asks for input using GetInt(), which it sounds like you have figured out. and then you write a piece of code (a loop might be pretty ...
user avatar
  • 1,317
6 votes

Tips on spaces and hashes Mario

Well, you wanted some tips, so here are a few thoughts on it. You know that you have to create the correct number of rows, you have that part. Now, you need to think about how to create the spaces ...
user avatar
  • 63.5k
5 votes
Accepted

How to debug "initialized element is not a compile-time constant" and "expected identifier" errors

You have the right idea behind how the code works, it's just your English to C needs some practice (understandably). int main(void); This is, as its name suggests, the "main" method. Essentially, ...
user avatar
  • 481
5 votes

How to approach Problem Set 1 Mario!

If the white space on the screen intimidates you, try outlining the problem on scrap paper. Think in broad terms, and describe what you're going to do in plain English before you write the code. Think ...
user avatar
  • 2,136
5 votes

pset1 mario - declaration shadows a local variable

With your usage of int you're creating a new variable. Example: int blocks = 5; {// Just creating a block, similar to a loop int blocks = 4; //Variable inside the block printf("%d\n", blocks); /...
user avatar
5 votes
Accepted

pset1 (mario, more) - problem with unwanted leading spaces

What conclusion can be drawn from these two facts? This loop for (row = 0; row <= height; row++) will generate height + 1 lines of output (0 through height inclusive) The first output line (ie row ...
user avatar
4 votes
Accepted

Mario Pyramid - Check50 - Unexpected end of input

Before you post a question, you should search to see if your question or a similar one had already been asked, in which case yours is. Check 50 returns unexpected end of input I suggest that you try ...
user avatar
  • 483
4 votes
Accepted

Output on Mario

I found a small but fatal glitch in your code. Have a look on you first loop in output part for (tower_height = 0; tower_height <= 23; tower_height ++) A moment before this line in your code, you ...
user avatar
  • 207
4 votes

Do do/while loops only take one line?

The syntax for do-while loop goes like this do { //do something here } while(test_condition); It is better to use braces {} every time you use loops. Although loops work even without their use, ...
user avatar
  • 3,316
4 votes
Accepted

Check50 tests fail with expected output, but not " ##\n"

You are printing one extra space character each row.
user avatar
  • 287
4 votes
Accepted

Pset1 : the mario question. I don't understand the logic of my own solution, it just doesn't make sense (found it by randomly playing around)

The value of s is increasing but the number of spaces it prints will be decreasing because you are inside the outer loop. Take your program and add some debug print statements like this: #include &...
user avatar
  • 18.4k
4 votes

Why do I get an "undefined identifier" error even though the variable is defined in my code?

In C all variable names have to be declared before they are used. If you try to use the name of a variable or a function that hasn't been declared you will get an "undeclared identifier" error. You ...
user avatar
4 votes

What's wrong with this code?

This line causes it: for (spaces = height - rows; spaces <= height; --spaces). While spaces is less than height, print a space and make spaces smaller. It is an infinite loop.
user avatar
  • 1,211
4 votes

any idea how to fix Mario more comfortable problem "expected output"

check50 is expecting the last # on a line to be followed by the newline. It is complaining about the trailing spaces.
user avatar
3 votes

do while loop not working?

Your condition is flawed. If x is greater than 0 OR x is less than 23, the loop will keep going. x > 0 includes all positive numbers, and x < 23 includes all negative numbers in addition to ...
user avatar
  • 182
3 votes

mario.c-printing of pyramid tower

Running the program: check50 should only be used to check your program before submitting it. To test your program while you're working on it, first run make to compile the program, then run mario to ...
user avatar
  • 2,625
3 votes
Accepted

Having Trouble tackling corner cases for Mario

You've declared your integer height inside the curly braces, so it is no longer in scope (no longer in existence) once you reach the end of the curly brace. I'm assuming you've also declared it ...
user avatar
  • 18.4k
3 votes
Accepted

Stuck on PSet1: I have the correct output, but Check50 says it's wrong

check50 is not wrong! Please check this question for more information about check50. Make sure you're in the same directory as mario.c and this is the command you run to check your program with ...
user avatar
  • 17.4k
3 votes
Accepted

C syntax errors like "expected expression"

It's a misplaced curly brace. do { int num = GetInt(); } while( int num < 0 || int num > 23 ); You want to enclose the do statement in curly braces, but keep the while condition outside....
user avatar
  • 18.4k
3 votes

How to Convert Integers to Spaces/Hashes?

If you use printf(" ") and printf("#") they will print one after another, when you need to go to the next line, just printf("\n")
user avatar
3 votes

What's wrong with my code for mario?

On lines 15 and 16, you are declaring two variables and initializing them to an empty space. int spaces = int hashes = This is very bad coding practice. Also, lines 23 - 27 have no function yet ...
user avatar
  • 483
3 votes
Accepted

Infinite loop when validating input as integer

From the comments above, it seems that you may have solved this already by using GetInt() from the cs50 library (and you should use it of course). But just if you're curious about why that happened, ...
user avatar
  • 17.4k
3 votes

Do do/while loops only take one line?

This error is because of the missing braces '{}'. Languages like python compile the code based on the indenting. However, C requires braces around do-while to compile correctly. Your code doesn't ...
user avatar
  • 85
3 votes

fatal error: 'stio.h' file not found (pset1)

Change it to #include <stdio.h> You've got a typo.
user avatar
  • 18.4k
3 votes
Accepted

Why is my `mario` pyramid height restriction not working?

The while condition in a do while loop is the condition that causes the loop to repeat. do { //this } while (this is true) Can you see why yours is incorrect? You have used the opposite ...
user avatar
  • 18.4k
3 votes

So Close on Mario Pyramid

the pseudocode for Mario for height of pyramid for (calculate nr. of spaces at height) print ' ' for (calculate nr. of hashes at height) print '#' print a newline I'd defer ...
user avatar
  • 458

Only top scored, non community-wiki answers of a minimum length are eligible