tc1017, Uncategorized

WSQ 04…

Here you can see my 4th programm. It had to ask for a range of numbers (integers) and then print the sum of that range of numbers, including the first and the last one. Basically it was a summation from the two values that were asked to the user. I knew what I had to do, but I wasn’t sure on how to include a summation in my programm, so I decided to ask Ken. I did an appointment and he helped me. I realized that it was very simple, I just had to put a ‘while’ condition that added one (+1)  to the first value until that value reached the second and at the same time added the value that were given by the first condition. (1+2+3….).

 

***IMPORTANT STUFF***

+If you have an appointment with Ken, he will not give you the answer but he will help you understand, and I think that is way better. Thanks again Ken!

2017-09-15

#WSQ04 #TC1017

Code:

#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;

int main()
{
int low;
int algo;
int total = 0;
int high;

cout << “Choose 2 numbers from 1-100 and type them, the first one should be smaller than the second one. “<< endl;
cout << “Type your first number from 1-100: “<< endl;
cin >> low ;
cout << “Type your second number from 1-100: “<< endl;
cin >> high ;

algo = low;
while ( algo <= high/* condition */) {
total = total + algo;
algo = algo + 1;/* code */

}
cout << “The sum of “<< low <<” and “<< high << ” is ” << total<< endl;

return 0;
}

Standard

Leave a comment