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


Temperature

--Originally published at Tec Life

This was the problem:

Write a program that will prompt the user for a temperature in Fahrenheit and then convert it to Celsius. You may recall that the formula is C = 5 ∗ (F − 32)/9.

Modify the program to state whether or not water would boil at the temperature given.

So I start coding normally “Declaring variables, including libraries, and in the main put the text that I will need in the problem”.

After asking the user the Fahrenheit degrees, I give value to the celsius degrees with this formula: C = 5 ∗ (F − 32)/9, and that was all in order to convert Fahrenheit to celsius, then I put my condition  in case if the result is bigger than 100. I start my condition with an “If” and next to it the conditions and I put what would happen, and then I put and else in case that this condition were not true.

captura-de-pantalla-2017-01-23-a-las-08-39-12

 

#WSQ02

Image from: http://climateresources.net


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


Temperature

--Originally published at Loading…

This was easy. Ken ask us to make a program…

“That will prompt the user for a temperature in Fahrenheit and then convert it to Celsius. Modify the program to state whether or not water would boil at the temperature given.”

As always the first thing that I did was to declare my variable. Then I put the cout instruction for show the question, and the cin for the user could write the temperature. After I write the formula for convert the Fahrenheit in to Celsius. And this was my code:

tempphoto

But it wasn’t as easy as it shows ‘cause I’m very distracted and I forget many things so it didn’t compiled very well 😞

TempPhoto2.jpg

SECOND PART

After all the mess that I did, Ken told me to be a pro and make my program said the state of the water at that temperature… I know that I can make it with an if instruction, but I forgot how I can use 3 conditions in an if, so I searched in St. Google and I found a page that helped me to finish my program, and this is my final code:

tempphoto3tempphoto4


Quiz #3

--Originally published at Programming 101

Hello guys! Today we had our third quiz and basically it was about wiritting a program that returned the square and the cubic root of a number. In the possible scenario that the user typed in a negative number, the program is supposed to give an appropriate answer.

Well, here is my code and the run program with the two possible outcomes, the one when the program gives the square and cubic root of a number and the one when the program receives a negative number.

Cheers, everyone! Stay awesome.

 

captura-de-pantalla-10

captura-de-pantalla-9


Cómo quiere su raíz

--Originally published at Adal´s Blog

La actividad dice así:


Para poder usar este programa necesitamos acudir a expresiones matemáticas alternas, como por ejemplo, expresar la raíz cuadrada en forma de potencia y utilizar nuevas librerías (en este caso <cmath>)

Y así es como queda el código:


Pagina de ayuda;

Ask F° and I’ll give you C°

--Originally published at Programming Path

Hello! This is the summery of #WSQ02. The task was to write a program that will ask the user the temperature in Fahrenheit then convert it to Celsius and also if at that temperature the water boils.

This is my code:

temperatura

#include <iostream>
using namespace std;
int main() {
int a, b;
cout <<“Give the temperature in Fahrenheit? “;
cin >> a;

b = ((5*(a-32))/9);
cout << endl << “The temperature in Celcius is ” << b << endl;

if (b >= 100) {
cout << “At this temperature water does boil.”;
}
else {
cout << “At this temperature water DOESN’T boil.”;
}
cout << endl;
return 0;
}

In this program we had to use if.. else it is not that hard to understand, I think is one of the easiest to use. In this example we just need to tell the program that if the number that is given is equal or higher than 100 then the water boils else the water does not boils. That all there is to do, besides the formula to convert F° to C°.

Hope it helped you.


Temperature in Celsius

--Originally published at my programming blog

So this week my assignment was to ask the user to give me a temperature in Fahrenheit and my program would give the user the temperature in Celsius and tell him the state of water in that temperature.

I included some mastery topics, I used nested ifs, the use of ifs and elses.

It wasn’t hard, I enjoyed this assignment! I thought the use of ifs would be hard but I understood it pretty fast.

If you don’t understand the use of ifs, I’ll explain what I did, so I just put an if and inside that if I added another if and after that if an else. So first I thought okay.. if the degrees in Celsius are more or equal to a 100, water was gas, then inside that if I added if the degrees where less or equal to 0 water was  solid and if it wasn’t neither of them water was liquid.

This is my code:

screen-shot-2017-01-26-at-10-36-44-am

#include <iostream>
using namespace std;
int main()
{
int F, C;
cout<< “Do you want to convert Fahrenheit to Celsius?”<<endl;
cout<< “And know what is the state of water in that temperature?”<<endl;
cout<< “Let’s begin!”<< endl;
cout<< “What is the temperature in Fahrenheit?”<<endl;
cin>> F;
cout<< “A temperature of “<<F<< ” degrees Fahrenheit is: “<<endl;

C=5*(F-32)/9;
cout<< C << ” degrees Celsius” << endl;
if (C>=100) {
cout<< “Water is in a gas state.”<< endl;
} else {
if (C<=0) {
cout<< “Water is in a solid state.”<< endl;
} else {
cout<< “Water is in a liquid state.”<< endl;
}

}
return 0;
}

And this how it looks once the program runs:

screen-shot-2017-01-26-at-10-37-39-am


Cuanta suerte tienes?

--Originally published at Adal´s Blog


Quieres probar tu surte con un divertido juego?


Para poder hacer este código me enfrente a un pequeño detalle, el hecho de que no sabia como generar números al azar, pero gracias a aprenderaprogramar.com, me dieron una ayudita de como hacerlo, se los dejo aquí ▼:



Pagina de ayuda: