Link of the picture:Link of the picture

So in this third class that i had on last Monday we started how to play with numbers and make a program for it in C++. If you need making a program using this techine in C++ check my last post: Second Class, Second Blog (Blog of the second class 12/01/17) and Hello World.cpp .

What i did for this numeric program is solving the problem to the user by asking the user for two integer values, then use those two values to calculate and show the following:

  • The sum for the two numbers
  • The difference of the two numbers
  • The product of the two numbers
  • The integer based division of the two numbers (so no decimal point). First divided by second.

The following photograph shows the solution to this problem:

fun-with-numbers

Picture of Author.

So at first i wrote the same structure of the program just did the same as what i did in Hello World: Second Class, Second Blog (Blog of the second class 12/01/17) and Hello World.cpp where i explained the application of the #MasteryTopic01 that it is for comments that could be very useful when debugging and #MasteryTopic04 that is basic output for data.

What i first put in the code was the library <iostream> to call all the fuctions of inputs and outputs of data in languague C++ #MasteryTopic06 Calling Functions and #MasteryTopic08 Importing and using libraries.

va

Then i had to write a command that everytime goes with the instructions of input and outputs of data that is call std but with this command helps writing these std out of the main because the machine factorizes them.

After that i had to declarate different basic types of variables in decimal and whole values for using in the math process #Mastery03 #MasteryTopic03  because that was a program where i need it use other type of variable in the part of the division to show in visualization of data with tools (terminal).

basicsvariable

Link of the picture: http://www.ntu.edu.sg/home/ehchua/programming/cpp/cp0_introduction.html

The new about this program from the Second Class, Second Blog (Blog of the second class 12/01/17) and Hello World.cpp is doing readings of input in data and mathematical processes #Mastery05 #MasteryTopic05 #Masterytopic05.

Just Remember the command for reading input in C++ is «cin>>»:

c3

Link for the picture: Link of the picture

AND REMEMBER NOT CONFUSE WITH PRINTING THE NUMERICAL VALUE IN TEXT!!!

For example:

If the command is this:

cout<<«The integer based division of the two numbers (so no decimal point)=»<<d<<endl;

This command is an output text where we can show the authentic output of the value entered ‘d’ in the terminal interface #MasteryTopic04 and the variable ‘d’ is NOT in the part of showing text.

As my errors and problems in doing this program were these:

  1. Using the operator for the remainder of integer division of the two numbers.
  2. Printing the wrong value of the remainder of integer division because of a semantic problem bug.

In the first error, I resolved it with the help of this link where showed me what and how was the operator of the remainder «%» working in C++ so this is the link: C++ Program to Find Quotient and Remainder

The second error of printing the remainder of the integer division was a semantic problem bug because the terminal did not show me at first the value of the remainder and the semantic bug was a wrong printing variable and the teacher helped me to see it and then solve this semantic error.

The following pictures shows the code of the program:

va

eee

f

And i also resolved it by doing this video tutorial that i made reafirming these parts at this link :#WSQ1 Second Tutorial Fun with Numbers 16/01/17

Finally with the command ./a. out tells the terminal to run de C++ file:

remainder

This code will be here and in Github:

Link in Github:Link in Github

If you do not want the WSQ1.cpp there is it in here with comments. The comments are very useful to detect errors and create new things #Mastery01 #Masterytopic01 #MasteryTopic01 #MASTERY01 #MASTERYTOPIC01 :

Also in this class i learned how to present my C++ in a better ‘readable’ way after doing it #Mastery02 #Masterytopic02 #MasteryTopic02 #MASTERY02 #MASTERYTOPIC02:

#include <iostream> //Library to call all the
//fuctions of inputs and outputs of data in languague
//C++ #MasteryTopic01

using namespace std; //In C++ we need a command
// that everytime goes with the instructions of input and outputs
//of data that is call std but with this command helps writing
//these std out of the main because the machine factorizes them

int main() //Begin of the program
{
float a,b,c; //Declarate decimal variables
int d,e,f,g; //Declarate whole variables

cout << "Give me one first number:"; //#WSQ1 command of out data in form of text
cin >> a; // This command allows enter data for inputs. In this case this enters the
//value of variable 'a'

g=a; // This command allows giving the value of the declared decimal variable 'a' to
//the declared whole variable 'g'. It converts one kind of decimal numeric value to
//a whole variable

cout << "Give me one second number:"; //#WSQ1 command of out data in form of text
cin >> b;// This command allows enter data for inputs. In this case this enters the
//value of variable 'b'

e=b;// This command allows giving the value of the declared decimal variable 'b' to
//the declared whole variable 'e'. It converts one kind of decimal numeric value to
//a whole variable

c = a + b; //This is a math operation between 'a' and 'b' and stands for adding
//those values and saved it in float variable 'c'
cout<<"The sum of the 2 numbers you put="<<a<<"+"<<b<<"="<<c<<endl; //#WSQ1 command of out data in form of text
//In this text we show the authentic output of the value entered of a,b and c in the terminal interface #MasteryTopic04

c = a-b;//This is a math operation between 'a' and 'b' and stands for take
//the difference between those values and saved it in float variable 'c'

cout<<"The difference of the 2 numbers you put="<<a<<"-"<<b<<"="<<c<<endl; //#WSQ1 command of out data in form of text
//In this text we show the authentic output of the value entered of a,b and c in the terminal interface #MasteryTopic04

c = (a*b); //This is a math operation between 'a' and 'b' and stands for take
//the product between those values and saved it in float variable 'c'
cout<<"The product of the 2 numbers you put="<<a<<"*"<<b<<"="<<c<<endl; //#WSQ1 command of out data in form of text
//In this text we show the authentic output of the value entered of a,b and c in the terminal interface #MasteryTopic04

d = a/b; //This is a math operation between 'a' and 'b' and stands for take
//the division between those values and saved it in whole variable 'd'
cout<<"The integer based division of the two numbers (so no decimal point)="<<d<<endl; //#WSQ1 command of out data in form of text
//In this text we show the authentic output of the value entered d in the terminal interface #MasteryTopic04
f = g%e; //This is a math operation between 'g' and 'e' and stands for take
//the remainder of integer division of the two numbers between those values and saved it in whole variable 'f'
cout<<"Remainder="<<f<<endl; //#WSQ1 command of out data in form of text
//In this text we show the authentic output of the value entered of f in the terminal interface #MasteryTopic04

return 0; // This command allows label the final of the function main ()

} //End of the program

 

 

 

Anuncio publicitario

12 comentarios en “#WSQ01 Post Fun with Numbers 16/01/17 and WSQ1.cpp

Deja una respuesta

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Salir /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Salir /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Salir /  Cambiar )

Conectando a %s