WSQ04 – Sum Between

--Originally published at The Talking Chalk

The Task

Create a program that asks for two integer values and prints the sum of all integer numbers between these values.

The Process

The Code

#include <iostream>
using namespace std;

int main ()
{
int big, low, sum=0;
cout<<“Give a number”<<endl;
cin>>low; //User gives value for low
cout<<“Now give a bigger number”<<endl;
cin>>big; //User gives value for big

do
{
low=low+1; //Sums 1 to low, so this low is a number between the original low and big
sum+=low; //Sums the value of low to sum
}
while(low<big); //the process repeats until low is equal to big, so sum will be the sum of all number between low and big
cout<<“The sum of the numbers between the two given is equal to “<<sum<<endl;
return 0;
}

The topics

#Basic output

#Basic input


WSQ03 – RANDOM

--Originally published at The Talking Chalk

The Task

Create a program that generates a random number within 1 and 100, leaving the user to guess which number it is.

The Process

The Code

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

int main()
{
srand(time(NULL)); //sets the random seed
int actual= rand() % 100 +1, given, counter=0; //Were actual be equal to “rand() % 100, it would have a value between 0 to 99”
cout<<“Guess the number, it has a value from 1 to 100″<<endl;
cin>>given;
count=count+1;
do
{
if(given>actual) //if given number is bigger than the actual one, the user will try again…
{
cout<<“Too high, give a smaller number…”<<endl;
cin>>given;
count=count+1;
}
else if (given<actual) // if given number is smaller than the actual one, the user will try again…
{
cout<<“Too low, give a bigger number…”<<endl;
cin>>given;
count=count+1;
}
}
(while given!=actual)//The loop will be done until given is equal to the actual number

cout<<“You got the right number!”<<endl<<“It took you “<<counter<<” times to get the right number”<<endl;
return 0;

}

The topics

#Importing and using libraries

#Transversal topic: Ability to create C++ file and run from command line (terminal)

 


WSQ02 – Boiling Water

--Originally published at The Talking Chalk

The Task

Create a program that converts farentheit degrees into celsisus degrees and explains if the conditions are proper for water to boil.

The Process

The Code

#include <iostream>
using namespace std;

int main()
{
int degress;
cout<<“Give me a temperature in Farenheit degrees: “<<endl;
cin>>degrees;
degrres = 5*(degrees − 32)/9; //Conversion from Farenheit to Celcius
cout<<“Your temperature in Celcius degrees is: “<<degrees<<“°C”<<endl;
if(degrees>=100)
{
cout<<“Water does boil at this temperature (under typical conditions)”<<endl;
}
else
{
cout<<“Water does not boil at this temperature (under typical conditions)”<<endl;
}
return 0;
}

The topics

#Use of conditional if

#else


WSQ01 – #GisIsTheNewChalk

--Originally published at The Talking Chalk

Chaos Has Arrived Like a Kangaroo…

As the world falls apart, the reindeers fly and the chaos arrives, a chalk is passing by…

Sin título

For sure this month has been quite bittersweet but that does not stop the chalk from passing by and talk. So here comes the brand new #GisIsTheNewChalk blogs.

The task

Ask the user for two integer values, then use those two values to calculate and show the following:

  • The sum of the two numbers.
  • The difference of the two numbers.
  • The product of the two numbers.
  • The integer based division of the two numbers (so no decimal point). First divided by second.
  • The remainder of integer division of the two numbers.

The process

Check this SABROSONGO video to know how to do this simple process.

The code

#include <iostream>
using namespace std;

int main()
{
int first, second;//Set the variables for the first and second number as integers
cout<<“Lend me an integer number…”<<endl; //To ask the user for the first number in a fancy way
cin>>first; //The variable first recieves a value
cout<<“Lend another one”<<endl; //Ask for the second number in a fancy way
cin>>second; //The variable second recieves a value

/*
We need to print the sum, substraction, multiplication, division and remainder of the division
*/
cout<<“The sum of these numbers is: “<<first+second<<endl;//Prints the sum of the two variables
cout<<“The substraction of these numbers is: “<<first-second<<endl;//Prints the substraction of the two variables
cout<<“The multiplication of these numbers is: “<<first*second<<endl;//Prints the multiplication of the two variables
cout<<“The division of these numbers is: “<<first/second<<endl;//Prints the division of the two variables
cout<<“The remainder of the division of these numbers is: “<<first%second<<endl;//Prints the sum of the two variables

return 0;
}