Post of the week #5 what things I learned in this week #5 ? And Index of Mastery Topics

--Originally published at Solving Problems with Programming

Picture of author

First let me tell you that  I learn and achieved all transversal topics and you can see it in the following link: Post of the week #3 what things i learned in this week #3 ? And Index of Mastery Topics

I also explain my project and formed a small team that corresponds of completing this ability to create C++ project in IDE and run inside the IDE and can be explained in my post My Project For the Course TC1017 and Expo Ing

Futhermore, I am going to present the report of all the Mastery Topics achieved in this week:

  1. #Mastery01 Use of comments, achieved in: Post of the week #2 what things i learned in this week #2 ?
  2. #Mastery02 C++ Good Style coding conventions, achieved in: Post of the week #2 what things i learned in this week #2 ?
  3. #Mastery03 Basic types and their use, achieved in: Post of the week #2 what things i learned in this week #2 ?
  4. #Mastery04 Basic output (print), achieved in: Post of the week #2 what things i learned in this week #2 ?
  5. #Mastery05 Basic user input (text based), achieved in: Post of the week #2 what things i learned in this week #2 ?
  6. #Mastery06 Calling functions, achieved in: #Quiz03
  7. #Mastery07 Creating functions, achieved in: #Quiz03
  8. #Mastery08 Importing and using libraries, achieved in: Post of the week #1 what things i learned in this week #1 ?
  9. #Mastery09 Creating and using your own libraries (program with multiple files), achieved in: #Quiz03
  10. #Mastery10 Use of the conditional “if”, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  11. #Mastery11 Use of “else” with a conditional if, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  12. #Mastery12 Nesting of conditional statements (ifs inside ifs): #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  13. #Mastery13 Use of
    recursion
    int-sumsquare
    double-function
    Continue reading "Post of the week #5 what things I learned in this week #5 ? And Index of Mastery Topics"

Post of the week #4 what things I learned in this week #4 ? And Index of Mastery Topics

--Originally published at Solving Problems with Programming

Picture of author

First let me tell you that  I learn and achieved all transversal topics and you can see it in the following link: Post of the week #3 what things i learned in this week #3 ? And Index of Mastery Topics

I also explain my project and formed a small team that corresponds of completing this ability to create C++ project in IDE and run inside the IDE and can be explained in my post My Project For the Course TC1017 and Expo Ing

Futhermore, I am going to present the report of all the Mastery Topics achieved in this week:

  1. #Mastery01 Use of comments, achieved in: Post of the week #2 what things i learned in this week #2 ?
  2. #Mastery02 C++ Good Style coding conventions, achieved in: Post of the week #2 what things i learned in this week #2 ?
  3. #Mastery03 Basic types and their use, achieved in: Post of the week #2 what things i learned in this week #2 ?
  4. #Mastery04 Basic output (print), achieved in: Post of the week #2 what things i learned in this week #2 ?
  5. #Mastery05 Basic user input (text based), achieved in: Post of the week #2 what things i learned in this week #2 ?
  6. #Mastery06 Calling functions, achieved in: #Quiz03
  7. #Mastery07 Creating functions, achieved in: #Quiz03
  8. #Mastery08 Importing and using libraries, achieved in: Post of the week #1 what things i learned in this week #1 ?
  9. #Mastery09 Creating and using your own libraries (program with multiple files), achieved in: #Quiz03
  10. #Mastery10 Use of the conditional “if”, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  11. #Mastery11 Use of “else” with a conditional if, achieved in: #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  12. #Mastery12 Nesting of conditional statements (ifs inside ifs): #WSQ02 Post Temperature 23/01/17 and WSQ02.cpp
  13. #Mastery13 Use of
    recursion
    int-sumsquare
    double-function
    Continue reading "Post of the week #4 what things I learned in this week #4 ? And Index of Mastery Topics"

Sum of numbers

--Originally published at my programming blog

This week the activity I needed to do was create a program that would ask the user for two numbers, the lower bound and the upper bound, and the program would give the user the sum of all the numbers from the lower bound to the upper bound.

I had some trouble with this because I was a little confused because every program from my classmates or on the internet were different so when Ken explained it in class I understood.

So what I did was:

  1. Named 3 integers, x,y and sum.
  2. I equaled sum to 0.
  3. Then I asked the user for the lower and upper bound.
  4. I used a while loop so if the user gave me a higher number in the lower bound the program would ask the user to enter the numbers in the right order.
  5. After that I used a condition where if the integers where in the right order there would be a for loop.
  6. In the for loop is like instructions, it is stated that while the int i that is equaled to x is less or equal to y the second number , i will increase.
  7. And then I equaled sum to i.
  8. Finally I printed the sum of the range.

The code:

#include <iostream>
using namespace std;
int main ()
{

int x, y, i, sum=0;
cout<< “Let’s to the sum of all the numbers in a range.”<<endl;
cout<< “Please give me the lower bound: “<< endl;
cin>> x;
cout<< “Please give me the upper bound: “<<endl;
cin>> y;

while (x>y){
cout<<“Please enter the numbers in the right order (from small to big).”<<endl;
cout<< “Please give me the lower bound: “<< endl;
cin>> x;
cout<< “Please give me the upper bound: “<<endl;
cin>> y;
}

if(x<=y){
for(int i=x; i<=y;

screen-shot-2017-02-08-at-11-24-21-am
screen-shot-2017-02-08-at-11-25-12-am
Continue reading "Sum of numbers"

Factorial Calculator

--Originally published at Loading…

This one was a little harder than the others, and it was a challenge to begin with because I couldn’t remember what is a factorial. But after I asked Ken and he explained me ( )…ie_factorial__6…the activity, it wasn’t too difficult. The activity consist in this:

Create a program that asks the user for a non-negative integer (let’s call that number n) and display for them the value of n! (n factorial).

After showing them the answer, ask them if they would like to try another number (with a simple y/n response) and either ask again (for y) or quit the program and wish them a nice day (if they answered n).

So, the first thing was do a function for the factorial, I established this function with the loop for, I wasn’t too sure of how doing it, so with the help of one page of Google and a classmate’s blog I could do it . In my main I established my variables as int and char, and then add the loop do/while for repeat until the user said no. Inside the “do” I put an if for the case that the number should be negative. This is my code:

factorial01factorial02

And this is how it works ?:

factorial03


Numbers… again?

--Originally published at Loading…

Yes, but this activity was different, the #WSQ04 said:

Write a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).

You can use a formula to calculate this of course but what we want you to do here is practice using a loop to do repetitive work.

This one was easy, don’t even need to add an extra library. And because I don’t start the chapter 3 of the book yet (#sorry ☹️), I decided to do it with the functions and loops that I already know. First I read the hole activity very well, and checked my other classmate’s works to understand how to do it, and in my head I made a flowchart.

As usually first I established my variables as int, put the “instructions” using cout, and wrote the operations. Then I added an if for the condition that both numbers were equal, and in the else part I put the do/while loop for make the addition. So, this is the code in the easy form, with nothing extra:

num

After proving that the program runs correctly, I decided to do my “extra” 💪🏼, so, I added an else if  for the condition that the “higher” number was lower than the “lower” number. Everything that I did was, literally, copy/paste what I already had and insert it inside the function. And voilà ? this is my code at the final:

num3num2

?

num4


Guess the number

--Originally published at my programming blog

The assignment is to create a program in which  you need to guess the number the computer was thinking, and if you get it wrong the program tells you if its too high or to small and when you get it right it tells the number of times it took you to get it right.

Here is my code:

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main (){
int x, secret,y=0;
srand(time(NULL));
secret=(rand()%100+1);
cout<< “I chose  a number between 1-100, can you guess it?: “<<endl;

do {
cout<<“Write your guess:”<<endl;
cin>>x;
y=y + 1;
if(x>secret){
cout<<“Wrong! ” <<x<< ” is too high, try again.”<<endl;
} else {
if (x<secret){
cout<<“Wrong! “<<x<< ” is too low, try again.”<<endl;
}
}
}while(x!=secret);
cout<<“Congratulations you got it right!!”<<endl;
cout<<“It took you “<<y<<” times to get it right.”<<endl;
return 0;
}

screen-shot-2017-01-31-at-7-40-53-amscreen-shot-2017-01-31-at-7-42-10-am

  1. I included the libraries “cstdlib” and “ctime” so that I could use the srandom function and the time function.
  2. Then I named my variables (the integers “x”, “y” and “secret”)
  3. I wrote the function of srand and inside the parenthesis I wrote time(NULL) so that the random number is always different.
  4. Then I equaled the integer “secret” to the random function “rand” and put %100 +1 to specify that I want a number between 1 and a 100.
  5. I added the cout to ask the user for a number.
  6. I made a loop called do-while, this means that while a condition is true this loop will repeat, so I did it with the condition that x!=secret, so while the user doesn’t guess the secret number this will repeat itself.
  7. Inside the loop I added an if so if x>secret the program tells you your number is too high, and another if so if
    Continue reading "Guess the number"

Your chance to make the first impression

--Originally published at Programming Path

Hello! The task, #WSQ03, that I’m publishing covers the #Mastery12 and #Mastery13.

I’m not that inspired, but I will try to do the best.

The activity was to do a program that choose a random number and the user tries to guess it. To do this, I needed to insert a new library <cstdlib> because this one has the code to generate random numbers. Also, I used do…if…while because I had to put conditions.

Here is picture of the code:

random

Here is just the code:

#include <iostream>
#include <cstdlib>
using namespace std;

int main () {
int a, b, c=0;
srand(time(NULL));
cout << “I picked a number between 1 and 100.” << endl;
cout << “Guess the number I chose: ” << endl;
a = rand()%101;
do {
c = c + 1;
cin >> b;
if (b > a) {
cout << “Wrong! Your number is too high, try again: ” << endl;
}
else if (b < a) {
cout << “That’s not the one. Your number is too low, guess again: ” << endl;
}
else if (b = a) {
cout << “Excellent! You did it! That’s the right number!” << endl;
}
} while (a != b);
cout << “Your total of guesses: ” << c;
return 0;
}

Thanks for reading.


Sum of Numbers

--Originally published at Tec Life

This was the problem:

Write a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).

You can use a formula to calculate this of course but what we want you to do here is practice using a loop to do repetitive work.

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

I start declaring normally my variables as integers and one different that I give him a value “suma= 0” later I will explain that, and one variable as character “con”.

I start my main asking the user t put the ranges of the sum and then I put and if in case if the range one was lower than the range two.

Then I put a loop with a loop while that says that the result is going to be equal to the result plus one while range one be lower than range two and every time that the operations happens range one is going to be one number more that it was until be the same as range two, and finally put the result of the sum.

captura-de-pantalla-2017-01-23-a-las-09-09-43

#WSQ04

Image from: http://www.clipartbro.com/categories/greek-symbol-for-sum-clipart


Pick a Number

--Originally published at Tec Life

This was the problem:

Write a program that picks a random integer in the range of 1 to 100.

There are different ways to make that happen, you choose which one works best for you.

It then prompts the user for a guess of the value, with hints of ’too high’ or ’too low’ from the program.

I start adding the libraries that I search on internet “stdlib.h” and “time.h” to make the program to generate one random number, then I declare my variables as local variables because there are going to change and I start coding the thing that I need to make the program give me a random number, that says that is going to generate one random number between 1 and 100.

Then I make a loop in case if I don’t guess the random number that the program makes, and I put if the number I put randomly in order to guess the other number was less that it was the program is going to say me that the number insert was to low, and one in case it would be to high.

And if I guess it the program is going to say me congratulations :).

captura-de-pantalla-2017-01-23-a-las-09-31-34

#WSQ03


I have a number chosen between 1 and 100.

--Originally published at Loading…

The activity was:

Write a program that picks a random integer in the range of 1 to 100.

It then prompts the user for a guess of the value, with hints of ’too high’ or ’too low’ from the program.

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

So the first step was to remember how to generate random numbers, and as always I searched it in St.Google, and I found a very good page that helped my a lot. I add the <ctime> and <cstdlib> libraries to make the program works. Then I established my 2 variables with int, I wrote srand(time(NULL)), for make the number always random, and the equation.

To make that the program continue until the user guesses I add a do/while function, that includes an if function to set the parameters and give the hints of ‘too high’, ‘too low’ or BRAVO, if you guess. Before to making something more pro, I wanted to be sure that it works correctly, I compiled and guess what… It didn’t do it, you will never guess the number, i don’t know why but it change it every time, so I looked for help and I found it in a classmate’s blog, he has a char command with a condition, so I try it in my program and it works, so that was the solution. At the final I add an extra variable to count the opportunities, and an if to show if your a loser or a winner. This is my code at the final:

randrand02