My entry to : Basic programming course: Lesson #2 - Variables and Types of Data

in #devjr-s20w22 months ago

Hi friends,

I am Jyoti from India. Hope you are all well and safe, here I am going to participate in the SEC S20 W2 contest: https://steemit.com/devwithseven/@alejos7ven/basic-programming-course-lesson-2-variables-and-types-of-data-esp-eng organised by @alejos7ven .

I have already learned C and C Plus Language Course so these lessons are very easy for me to learn but since it has been a long time it is very helpful for me to recall.

Copy of @jyoti-thelight (3).jpg

SOURCE

Variables and Types of Data

What are variables and what are they used for?

Variables

A variable is basically nothing but the name of a memory location that we use to store data. In any other language, you can change the value of a variable and reuse it many times. We use symbols in variables to indicate the memory location - so that any user can easily identify it

Use of Variables

Variables are areas of storage in the code of language that can be easily manipulated by the program. Each variable in the C language has some specific type—which determines the variable's layout and size of memory, the range of values ​​the memory can hold, and the set of operations one can perform on that variable.

A variable name can be a combination of digits, letters, and underscores. The character name must begin with an underscore or letter.

Assign a type of data to the following variables and explain why: email, phone, working_hours, price_steem, and age.

"email" is a string. An email is a sequence of characters, typically containing letters or numbers and symbols so it is a string data type.

"phone" is also a string since a phone number is a series of characters that includes numeric characters, making it a string data type.

"working_hours" is a tuple. Because it stores the value of working hours including of a start time and an end time, it is a tuple data type.

"price_steem" is a float. The price or value of currencies can have decimal values such as 40.108, so it is a float data type.

"age" is an integer. Because age is typically known as a whole number ex. 40, so it is an integer data type.

Explain how the following code works:

Algorithm names
Define name, last_name as Character;
Print "Enter your name:";
Read name;
Print "Enter your last name:";
Read last_name;
Print "Hello " name " " last_name ", welcome";
EndAlgorithm

This simple algorithm prompts the user to enter their name and last name and then greets them with a welcome message. Here's a step by step tutorial of how it works:

The first line declares two variables, name, and last_name, as characters. This means that they will be used to store strings of characters, such as the user's name and last name.

The next line print (displays) the message "Enter your name:" in the console, requesting the user to enter their name.

The Read command reads the user's input from the console and stores it in the name variable.

The next line prints the message "Enter your last name:" to the console, prompting the user to enter their last name.

The Read command reads the user's input from the console and stores it in the last_name variable.

Finally, the last line prints the message "Hello [name] [last_name], welcome" to the console, where [name] and [last_name] are replaced with the values stored in the name and last_name variables, respectively.

Develop a pseudo-code to calculate the value in USD of X STEEM. For this you can rely on this algorithm:

Declare variables price_steem, total, and amount_steem.
Request the user for the necessary data.
Calculate as follows: total = amount_steem*price_steem.
Show the result on the screen.

Algorithm calculate_steem_value
Declare price_steem, total, amount_steem as Real;
Set price_steem = 0.1626; // 1 STEEM is equal to 0.1626 USD
Print "Enter the amount of STEEM:";
Read amount_steem;
Set total = amount_steem * price_steem;
Print "The value of " amount_steem " STEEM is " total " USD.";
End Algorithm

This algorithm first declares three variables: price_steem, total, and amount_steem, all of which are of the Real data type.

Let us see the results in C compiler, for this test I used an online C compiler called programiz

Step 1: Declare price of steem

image.png

Step 2: Declare amount of steem and value with USD

image.png

Step 3: Run to check the result

image.png

Step 4: Code Execution Successful

image.png

I like to invite
@riya01,
@suborna03 ,
@dave-hanny, to take part in this contest.

💚THANK YOU 💚

Discord : @jyoti-thelight#6650 Telegram :- https://telegram.org/dl

jo.gif

Sort:  
Loading...

Congratulations, your post has been upvoted by @scilwa, which is a curating account for @R2cornell's Discord Community. We can also be found on our hive community & peakd as well as on my Discord Server

Manually curated by @ abiga554
r2cornell_curation_banner.png

Felicitaciones, su publication ha sido votado por @scilwa. También puedo ser encontrado en nuestra comunidad de colmena y Peakd así como en mi servidor de discordia

Thank you very much

Upvoted! Thank you for supporting witness @jswit.

Upvoted. Thank You for sending some of your rewards to @null. It will make Steem stronger.

Hello @jyoti-thelight may i participate in the contest, rightnow 'm not verified...

hello dear.. it will be my great.. agar aap meri help kar do.. maine aapko discord per friend request bheji hain.. please accept it...