Nintendo – Writing Super Mario Bros In C++

Toward the beginning of World 1-1 in Nintendo’s Super Mario Brothers, Mario must hop over two “half-pyramids” of blocks as he heads toward a flag pole. Below is a screenshot.

Đang xem: Nintendo

*

Write, in a file called mario.c in your ~/workspace/pset1/mario/more/ directory, a program that recreates these half-pyramids using hashes (#) for blocks.

To make things more interesting, first prompt the user for the half-pyramids” heights, a non-negative integer no greater than 23. (The height of the half-pyramids pictured above happens to be 4, the width of each half-pyramid 4, with an a gap of size 2 separating them.)

If the user fails to provide a non-negative integer no greater than 23, you should re-prompt for the same again.

Xem thêm: Learn How To Download And Install Your Creative Cloud Apps, Log In To Adobe Creative Cloud

Then, generate (with the help of printf and one or more loops) the desired half-pyramids.

Take care to left-align the bottom-left corner of the left-hand half-pyramid with the left-hand edge of your terminal window.

Xem thêm: Macos Catalina Is The End Of The Road For Indesign Cs6, Photoshop And Catalina

Walkthrough

Usage

Your program should behave per the example below. Assumed that the underlined text is what some user has typed.

$ ./marioHeight: 4 # # ## ## ### ####### ####
$ ./marioHeight: 0
$ ./marioHeight: -5Height: 4 # # ## ## ### ####### ####
$ ./marioHeight: -5Height: fiveHeight: 40Height: 24Height: 4 # # ## ## ### ####### ####

Testing

Correctness

check50 rev-conf.org/2018/spring/mario/more

Style

style50 mario.c

Staff Solution

~rev-conf.org/hacker1/mario

Hints

Try to establish a relationship between (a) the height the user would like the pyramid to be, (b) what row is currently being printed, and (c) how many spaces and how many hashes are in that row. Once you establish the formula, you can translate that to C!

Leave a comment

Your email address will not be published. Required fields are marked *