WSQ 04- Sum of numbers.

--Originally published at |Blogging through my thoughts|

¡Hello , programmer and curious friends! This is my fourth program , created using Cygwin and Atom. For this task , my classmates and I were instructed to create a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).

For example, the sum from 6 to 10 would be 0 + 6 + 7 + 8 + 9 + 10.

I decided to use a loop to calculate the sum, because my programming teacher Ken Bauer, wanted us to practice repetitive work.

The resources that helped me were:
-How to think like a computer scientist.

-cpluplus.com

-Programming hub, mobile app.

I added some extra steps, because I wanted to show more information to the users , like:

-Both numbers are the same. Give me a correct range.

– The sum is also executed if the user writes the upper and lower bound in the wrong order.

Here you will find my code and some captures:

wsq04-cygwin
Running on Cygwin.
wsq04-code
Atom code.

#include
using namespace std;

int sum(int min,int max);

int main(){
cout << “This program prints the sum of numbers in a range(inclusive):” << endl;
int a,b;
cout << “Enter the lower bound:” << endl; cin >> a;
cout << “Enter the upper bound:” << endl; cin >> b;

if (a<b){
cout << “The sum from ” << a << ” to ” << b << ” is: ” << sum (a,b) << endl; } else if (a>b){
cout << “The sum from ” << a << ” to ” << b << ” is: ” << sum (b,a) << endl;
}
else {
cout << “Both numbers are the same. Give me a correct range.” << endl;
}
return 0;
}

int sum (int base , int limit)

wsq03-topics
wsq04-topic
masterytopics1
Continue reading "WSQ 04- Sum of numbers."

WSQ 03 – Pick a number.

--Originally published at |Blogging through my thoughts|

This is my third program, created using Cygwin and Atom.

The task was to create a program that picks a random integer in the range of 1 to 100. After that , the game starts when the user has to guess which number does the program picked, with hints of ’too high’ or ’too low’.

The program continues to run until the user guesses the integer.

I added some extra steps, because I wanted to show more information to the users , like:

-How many guesses they had to make to get the right answer.

 

The resources that helped me were:
-How to think like a computer scientist.

-cpluplus.com

-Programming hub, mobile app.

 

Here you will find my code and some captures:

wsq03-code
Atom code.

#include <iostream>
#include <stdlib.h>   // srand , rand
#include <time.h>     // time
using namespace std;

int main(){
int secret , guess, attempts;

cout << “This program picks a random integer in the range of 1-100.” << endl;
cout << “***In order to win , you need to guess the number***” << endl;

srand (time(NULL));               // Initialize random seed
secret = rand() % 100 + 1;

do {
cout << “Write your guess:”<< endl;
cin >> guess;
attempts=attempts+1;

if (secret<guess){
cout << “The secret number is lower.” << endl;
}
else if (secret>guess){
cout << “The secret number is higher.” << endl;
}
} while (secret!=guess);

cout << “You won , congratulations!” << endl;
cout << “It took you ” << attempts << ” attempts.” << endl;
return 0;
}

wsq03-cygwin
Running on Cygwin.

wsq03-topics

masterytopics1
Mastery topics involved.

 

Until next time.

°Luis Felipe Garate Moreno.

 


My first c++ program , using atom and cygwin.

--Originally published at |Blogging through my thoughts|

Hello dear readers. This is my first post and it is of great importance, because it reflects the beginning of the programs that I will create throughout the semester. 

“Fun with numbers” is the first problem that Professor Ken Bauer assigned us.  The task was to create a program that complies with the points shown in the image and thereby solve the problem.

It was a challenging activity, which helped me learn basic commands for c ++ . The language is simple to understand once you study a little. The book “How to think like a computer scientist” was very useful to conceive my code, in addition to several videos of youtube.

I hope you enjoy my program and really understand the whole code ?

Luis Felipe Garate Moreno.

atomfwn1
Atom program – My code.

#include <iostream>
using namespace std;

int main()
{
int a,b,r1,r2,r3,r4,r5;  //Declaration of variables , r=result.

cout <<“This program performs several operations from two numbers and provides the results” << endl;
cout << “Give me the first number:” << endl;
cin >> a;       //Variable for the first number.
cout << “Give me the second number:” << endl;
cin >> b;       //Variable for the second number.

r1 = a + b;   //Sum
cout <<“The sum of the two numbers=” << r1 << endl;
r2 = a – b;   //Subtraction
cout <<“The difference of the two numbers=” << r2 << endl;
r3 = a * b;   //Multiplication
cout <<“The product of the two numbers=” << r3 << endl;
r4 = a / b;   //Division
cout <<“The integer based division of the two numbers=” << r4 << endl;
r5 = a % b;   //Remainder of integer division
cout <<“The remainder of integer division of the two numbers=” << r5 << endl;

return 0;
}

_____________________________________________________________

cygwinfwn1
Cygwin commands.

 

masterytopics1
Mastery topics
Continue reading "My first c++ program , using atom and cygwin."

WSQ 02 – Temperature.

--Originally published at |Blogging through my thoughts|

This is my second program , created using cygwin and atom. For this task , my classmates and I were instructed to create a program that will prompt the user for a temperature in Fahrenheit and them convert it to Celsius. The formula that made the conversion possible was  C = 5 ∗ (F − 32)/9  (where F = Fahrenheit).

The resources that helped me were:
-cpluplus.com
-How to think like a computer scientist.

I added some extra steps to show more information to the user , depending on the number (x) given , like if:

-Water boils at x temperature.

-Water is in its solid state, ice.

-Water, in its solid state, becomes liquid due to its melting point.

-Water does not boil at this temperature.

It really was a fun and entertaining task.

 

Here you will find my code and some captures:

wsq02-code
Atom code.

-Atom code:

#include <iostream>
using namespace std;

int main(){
int f,c;

cout << “This program converts temperature from Fahrenheit to Celsius.” << endl;
cout << “Give me the temperature in Fahrenheit:” << endl;
cin >> f;
cout << “The temperature is ” << f << ” Fahrenheit” << endl;

c = 5*(f-32)/9;
cout <<“The temperature expressed in Celsius is ” << c << ” Celsius” << endl;

if (c >= 100){
cout << “Water boils at this temperature.” << endl;
}
else{
if (c < 0){
cout << “Water is in its solid state, ice.” << endl;
}
else{
cout << “Water, in its solid state, becomes liquid due to its melting point.” << endl;
cout << “Water does not boil at this temperature.” << endl;
}
}
return 0;
}

wsq02-cygwin
Running on Cygwin.

 

wsq02-topics

masterytopics1
Mastery topics involved.

 

 

Until next time.

°Luis Felipe Garate Moreno.