DEV Community

Cover image for Programming in C++ (Part 1 Variables)
Mark Mahoney
Mark Mahoney

Posted on • Edited on

Programming in C++ (Part 1 Variables)

Simply watching an experienced artist paint is not enough to say that you have learned how to become a painter. Watching an experienced artist is an important part of the learning process but you can only call yourself a painter after struggling to make your own paintings first. There are a lot of similarities between learning to paint and learning to program. The only way to truly learn programming is through practice!

So, let's get started. Follow along with the code playbacks below. Click the links below to load each code playback (it may help to open them in a new tab). Click on the playback comments on the left-hand side of the playback screen to step through the code's development.

Flow of Control

In the following program I begin to discuss the flow of control in a program by describing how to print to the screen from a program:

Variables and Types

This next group of programs describes declaring variables to hold data in a program. All variables have a type which specifies what can be stored in them and what operations can be performed on them.

Reading from the Keyboard

This final group of programs builds on previous concepts and shows how to prompt the user for input.

Call to Action

Now that you have reviewed the guided code walk-throughs in this post, I ask that you write a program that prompts the user for three integers- one representing an hour, one representing a minute, and one representing a second. Next, calculate the number of seconds until midnight based on the time that was input. Print the number of seconds until midnight on the screen.

Then, prompt the user for a single integer representing the number of seconds until midnight. From that value, do the reverse calculation to find the hour, minute, and second of that time. Print it to the screen in a time format HH:MM:SS.

After you are done, you can move on to the next part in the book Part 2: Selection. Or, go back to the series main page.

Comments and Feedback

You can find all of these code playbacks in my free 'book', An Animated Introduction to Programming in C++. I am always looking for feedback so please feel free to comment here or to send me a direct message.

Top comments (1)

Collapse
 
basman profile image
Adam.S

Hi,
It would be nice if you could make this into a series. This would link all the C++ articles together.