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


#Quiz03

--Originally published at Solving Problems with Programming

PICTURE OF AUTOR

THIS IS THE #QUIZ03 WHOSE OBJECTIVE IS CREATE AND CALL FUNCTIONS TO DO DIFFERENT TASKS AT DIFFERENT TIMES. COVERING #MASTERYTOPIC06 #MASTERYTOPIC07 .

This #QUIZ03 makes a main routine that asks the user for a number and then calls your functions to calculate the square and cube roots of that number and prints them out. And if the number given is negative. It is going to print the cube root number but in the square root it will tell the user that the number given for that root is IMAGINARY! (#Mastery11).

FIRST TO DO THIS #QUIZ03 I HAVE TO USE THE LIBRARY FOR THE COMMANDS OF MATH THAT WOULD BE SQRT FOR SQUARE ROOT AND CBRT FOR THE CUBE ROOT AND I FOUND THE NAME OF THE LIBRARY IN THE BOOK OF THE COURSE THAT IT IS CALLED #include<cmath>:

library

Link of the book that told me the name of the math library: How to Think Like a Computer Scientist C++ Version by Allen B. Downey.

And also for the name of the commands i used for information this link: function <cmath> cbrt and this link: function <cmath> sqrt

cube2

PICTURE OF AUTOR

funx

PICTURE OF AUTOR

SO AT FIRST THING YOU DO THE SAME AS OTHER PREVIEW CODES DECLARATE YOUR TYPE OF VARIABLE AND YOUR VARIABLE AND ASK THE USER TO GIVE YOU A NUMBER.

AFTER THAT YOU HAVE TO CALL YOUR CREATED FUNCTIONS THAT WERE:

  • double square_root(double x) {}  // returns the square root of x
  • double cube_root(double x) {} // returns the cube root of

YOU HAVE TO KNOW THAT USING THESE 2 FUNCTIONS IS OTHER EXTERNAL FUNCTIONS FROM THE MAIN THAT HAS A DOUBLE FUNCTION VALUE OF 64 BITS AND DECLARING A DOUBLE VARIABLE X INSTEAD OF USING THE VOID MAIN THAT HAS 0 BITS.

TO CALL THE FUNCTION IN THE MAIN

new
Continue reading "#Quiz03"

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:

Second assignment – Temperature

--Originally published at The Clueless Programmer

Here I go again, clueless programmer on the go hitting you up with another awesome blog post. That´s what I would say if I indeed made awesome blog posts. Anyway, let´s get right to it.

This time the assignment was more difficult than the last one, but still, I managed. This was the first program that asked us to use an “if” conditional (a conditional that only applies if you trigger the if).

imagen1

#include <iostream>
using namespace std;
int main()
{
int n1, n2;
cout<<“Write the temperature in Fahrenheit degrees: “;
cin>>n1;
n2=(5*(n1-32))/9;
cout<<n1<<” Fahrenheit degrees convert to “<<n2<<” Celsius degrees”<<endl;
if (n2>=100)
{
cout<<“Water boils at this temperature”<<endl;
}
else
{
cout<<“Water doesn´t boil at this temperature”<<endl;
}
}

There you have the program!

Basically what I do is ask you for a temperature in Fahrenheit degrees, which I save on a variable, then on another variable I save that Fahrenheit temperature converted into a Celsius one. Then I put the ifs down, if the conversion is bigger or the same as a hundred, water boils at that temperature, if it is lower, it doesn´t.

Simple stuff right? (I can bet karma will hit me up with a really difficult assignment really soon, but I´ll enjoy my time until then). So yeah hope you learned something, as always thanks for reading me and hang in there, program on.

 


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