# Sum of numbers

La explicacion del programa esta en el siguiente video  # Sum of Numbers #WSQ07    # WSQ07 – Sum Of Numbers

## SUMA DE NÚMEROS Como el título lo dice, este programa te muestra una suma de un número al otro, el usuario selecciona los rangos que el desee, siempre y cuando el segundo rango sea mayor que el primero.

En este código se tienen 3 valores: a (primer rango), b (segundo rango) (con valor de 0), lo “complicado de realizar este programa es el de sumar hasta llegar al segundo rango.

El sigificado de: a++;} es que va aumentando de uno en uno aparte de a hasta llegar a b  Link de GitHub: WSQ07 – Sum Of Numbers  # #WSQ07 – Sum of Numbers

This program will sum all the integers in a range provided by the user(low and high).

But the thing gets more intersting when you add a condition, what if the user enter the range flipped. My solution was simple, using another variable(joker) to keep rolling the values of the variables until the boundries are flipped. Also used a counter and a while loop, because you start at the lower value(once you flipped if needed) and you know that the point to stop will be de upper value, so you just keep to adding 1 to the lower value and keep adding it to the same lower value. At the end joker is equal to lower, because you need the original value of lower if you want to display to the user, just to remaind them, the range they provide.

#TC101  # Range between numbers

#TC1017 #WSQ07

This problem was actually a little more difficult to solve than the previous ones. Although it does what it needs to do, I think I made things somewhat more complicated than they needed to be, which is why I added some comments to remind myself what I did and why.

The programm begins by asking the user for two numbers, for which it will calculate the total sum of the numbers inbetween, inclusive. First of all it checks that the numbers given are in the proper order: lower to higher, then I use the difference between those numbers to calculate the amount of sums that have to be done and add a -1 so the difference matches the quantity of numbers between them properly.

Once that has been done, the programm then sums the numbers n times using a while loop until the counter (n) matches the quantity of numbers between the ranges.

As I said, a little complicated but it works! Source Code:

#include <iostream>
using namespace std;

int main(){

int lower, higher;
int difference, sum;
int counter;
int loweract;

cout <<“Please enter the lower bound:” << endl;
cin >> lower;
cout << “Please enter the higher bound:” << endl;
cin >> higher;

while (lower > higher) {

cout << endl;

cout <<“Please enter the lower bound:” << endl;
cin >> lower;
cout << “Please enter the higher bound:” << endl;
cin >> higher;

}

do { //could this be done with a for loop?

difference = ((higher – lower)-1); // gives the number of integer sums aside from the bounds
counter ++; // counter is needed so that the sum stops once the counter reaches the number of sums
loweract = lower + counter  # Sum of Numbers #WSQ07

This program’s objetctive was to sum the numbers between 2 numbers typed by the user. It wasn’t hard to do it, a while was enough to run the program.

Example:

number 1: 3;
number 2: 9;

Sum of numbers: 3 + 4 + 5 + 6 + 7 + 8 + 9 = 42;    # Sum of numbers (WSQ07)

On this blog I’ll develop a code that asks the user a range of numbers and the program will return the sum of all numbers of that range.

To get started, we need to ask the user for the range of numbers with an input: After that, is necessary to convert the inputs to integer numbers so our program can run without problems. Every number in python needs to have a type of number, it depends of what you need to do. For this program, I’ll use integers because this program does not need something more elaborated.

We also need a mathematical counter, I’ll explain later why. For now, we’ll give it the value of zero. Then, a loop is needed to do the whole mathematical process, because the program will sum each number of the range consecutively.

While programming the loop, you need to be careful so you don’t code things unnecesarily. (Like I did) All the comments are the lines that wasn’t needed but I wrote at first, until the teacher helped me out to optimize the code. The logic of the program is simple, the “cont” variable will sum the numbers of the range and the line #10 is the one that will increment the value of each  number of the serie as it advances.

Finally, we just print the result with the syntax that we already know. That’s it! We’re done with it!.

As always, I uploaded my code so you can check it.  # WSQ07 – Sum of Numbers

el código:

#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
int main()
{
int num1,num2,rest,resul,x;
resul=0;
cout<<“nWe will calculate the sum of integers in the range you provide.”;
cout<<“nPlease give us the lower bound: “;
cin>>num1;
cout<<“nPlease give us the upper bound: “;
cin>>num2;
rest=num2-num1;
for(x=0; x<=rest; x++)
{
resul=resul+num1;
num1++;
}
getchar();
return 0;  # Sum of Numbers (Credits goes to https://www.mathsisfun.com/algebra/sequences-sums-arithmetic.html)

For this WSQ we had to write a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).

To do this correctly I first read how does the formula work and in my research i found this page —> https://www.mathsisfun.com/algebra/sequences-sums-arithmetic.html and it helped me to understand what I needed to do, after thar it was easy to program this wsq, and here is my code in atom and ran in the terminal.

Haga click para ver el pase de diapositivas.

And of course here is my link to my code in github → https://github.com/mfcanov/SumOfNumbers-.git  