#include <iostream> #include <cstdlib> using namespace std; int main () { int a,b,c, s=0; cout<< “Rango” << endl; cout<< “Número a” << endl; cin >> a; cout << “segundo número” << endl; cin>>b; c=b-a+1; while (a<=b) { s=s+a; a++; } cout <<“La suma es de: ” << s << endl; }
This one took me a bit to get it. I didn’t quite get the whole for thing and range the first time, but after playing with it a little I got the hang of it pretty quickly. Anyways, here’s the code:
Sum of numbers Things are getting seriously interesting… and by that I mean.. weird, this last 2 WSQ were.. a whole new level of skill, hello world is a thing from the past. Now for these code you will need to know how to use while (in order to create a loop, that is an… More #WSQ07
Sum of numbers Things are getting seriously interesting… and by that I mean.. weird, this last 2 WSQ were.. a whole new level of skill, hello world is a thing from the past. Now for these code you will need to know how to use while (in order to create a loop, that is an… More #WSQ07
My head hurts a little because that loop was a hard one (for me) still it takes me a whie to figure out what I did there.
But it works so I can’t complain.
here it is: https://github.com/VanessaBaeza17/Sum-of-Numbers/blob/master/CODE
007
This WSQ was the hardest one I have done yet. The user had to enter two variables so the program did an inclusive addition of the two assigned values. For example: “2″ and “9″. What the program did was a sum of 2+3+4+5+6+7+8+9= 44.
I had a close result to the expected program but I missed some little details, so Ken helped me out a bit.
You can check my code here if you want:
In this activity, the goal was to create a program that sums the number of a range given by the user. It was a little bit complicated at first because I didn’t know that I had to equal the sum to 0. Then, I had some problems because it didn’t only showed the final result, it showed all of the sums, but then I realized that I had the “ } ” of the “while” after outputting the sum, so, I just changed it after assigning the last value to “c”, so that way it gets out of the loop, and it finally worked.
In this wsq the hard part was investigating the functions I needed to use, after understanding them it was easy. I used the loop while to indicate that while the lowest number of my range, is smaller than the highest number on my range, my program will execute and it will print the sum of … Continue reading #WSQ07 →
Hey there, this is #WSQ07 that gives the sum of a range of numbers given by the user. This task was more difficult than the other ones, but here it is! Remeber you can use wordsto declare variables, I didn´t but it may be easier to understand.
Sum of a RANGE of numbers. This WSQ was a little bit more difficult, than the ones before. I got inspiration from a friend’s code but I didn’t liked so I change some parts of his code. First I would like you to see my code. I tried used a function and a condition while […]