Quiz 4

--Originally published at Tec Life

For this quiz we have to do this:

For this quiz I want you to (in class) create a program with two functions:

  • int minimumThree(int x, int y, int z){ }  // returns the value that is smallest of x, y and z
  • int sumSquares(int x, int y, int z) {}  // returns the value of the sum of squares of x, y, z

You should make a main routine that asks the user for three numbers and then calls your functions to which should *RETURN* the value and you print in the main program.

So I started writing my program normally, declaring my variables, naming my functions and to make the user to write the three numbers.

captura-de-pantalla-2017-02-02-a-las-09-28-40

Then I make what my functions would do, that says in the first function that I am going to multiplied my variables with the function “pow” and in a parenthesis my variable “,” and the number I want to multiplied my variable, in this case 2 for square and the sum the operations.

And on my second function I put conditions with if and else to make the program know what number is bigger than the other and finally printed on the result.

captura-de-pantalla-2017-02-02-a-las-09-28-52Image from: http://www.quizfactor.com/quiz/general-knowledge/5

#Quiz04


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


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.


There was quiz today?!

--Originally published at Loading…

Yes, today we did our 3rd quiz, and it was… “easy”? At first, when I read what we have to do my face was a little like this 😕 because I didn’t read the chapter 3 and I don’t have idea what I have to do, but Ken show us a code, I Googled and compared it with some of the codes that my classmates had in their blogs, at the end I understand what I was doing with all that. This is my code:

qp qp2

First I had to add the <cmath> library in order to make my functions works, the square and cube root functions. Also I used double for my variables, so it could give me decimal numbers, I declared everything like the ecuation and the cout. After I add a if fuction, if the number that the user gives was negative, then a do/while start, so it ask for a new number, and a nesting of conditional statements for if the case repeats (negative number).

And this is how it runs:

qp3

I know it’s a little late, but I swear I did it in class.


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:

Third assignment – Pick a number

--Originally published at The Clueless Programmer

Okay so this assignment really tested me out, specially because I didn´t know anything about generating a random number or how to do it, but by reading the book (and asking a lot of questions) I figures it out. Let´s go.

The tasks asks us to make a program that thinks of a random number and then starts asking us to guess the number, telling us if we are lower or higher, once we guess it, it gets us out.

imagen1

#include <iostream>
#include <stdlib.h>//Library for the rand command
using namespace std;
int main()
{
int n1, n2;
char cond=’n’;
srand(time(NULL));//This makes the number always random
n1=rand()%101;//I use the 101 because it takes every number until the number you write
do
{
cout<<“Try to guess the number I´m thinking of”<<endl;
cin>>n2;
if (n2>n1)
{
cout<<“Your number is higher than the one I´m thinking of”<<endl;
}
else if(n2<n1)
{
cout<<“Your number is lower than the one I´m thinking of”<<endl;
}
else
{
cout<<“Congrats! You guessed it”<<endl;
cond=’s’;
}
} while(cond==’n’);
}

So okay you are confused, you see a lot of tricky stuff right? But don´t worry it will make sense, eventually.

First what you want to do is include the library that has the command for the random number generator. Then after you name your variables, you write that srand stuff, which basically what it does is change the random command so that everytime you enter the number is different. Then you write the rand command, I write 101 instead of 100 because it takes the number before the oe you write, so 0-100. Then we enter the do-while, which basically means it ill do something at first and then continue to do it while the condition isn´t fulfilled. I do the ifs and else in which I close out

Continue reading "Third assignment – Pick a number"

De F° a C° y estados de la materia

--Originally published at Adal´s Blog

La actividad del día de hoy es:

Como pueden ver tenemos que hacer un código que nos ayude a convertir los grados Fahrenheit a grafos Centigrados y ademas decirnos en que estado de la materia se encuentra el agua



Paginas de ayuda