This is the question:
Write a function which takes two parameter of integer type and both parameters are positive integer. These number should be provided by the user of your program. The first parameter is lower than the second parameter. You function should be able to calculate the sum of the square of each of the numbers between the two inputs and should display that. Please write a main function to display the working of your function. Call the function at least three times by using some loop in the main function.
This is what I came up with but it is not correct:
#include <iostream>
using namespace std;
void sumsquares(int number1, int number2)
{
int sum = 0;
for(int i = number1; i<number2; i++)
sum =sum+ i*i;
cout<<"The Result is: "<<sum<<endl;
}
int main()
{
int number1, number2;
cout<<"Enter two numbers "<<endl;
cout<<"Enter the first number: ";
cin>>number1;
cout<<"Enter the second number: ";
cin>>number2;
cin.get();
void sumsquares(int number1, int number2)
{
int total = 0;
for(int i = number1; i<=number2; i++){
total += i*i;}
cout<<"The Result is: "<<total<<endl;
}
int main()
{
int number1, number2;
cout<<"Enter two numbers, where the first is less than the second number "<<endl;
cout<<"Enter the first number: ";
cin>>number1;
cout<<"Enter the second number: ";
cin>>number2;
cin.get();
sumsquares(number1, number2);
cout<<"\n";
cout<<"Enter two numbers, where the first is less than the second number "<<endl;
cout<<"Enter the first number: ";
cin>>number1;
cout<<"Enter the second number: ";
cin>>number2;
cin.get();
sumsquares(number1, number2);
cout<<"\n";
cout<<"Enter two numbers, where the first is less than the second number "<<endl;
cout<<"Enter the first number: ";
cin>>number1;
cout<<"Enter the second number: ";
cin>>number2;
cin.get();
sumsquares(number1, number2);
cout<<"\n";
#include <iostream>
usingnamespace std;
void sumsquares(int number1, int number2)
{
int total = 0;
for(int i = number1; i<=number2; i++){
total += i*i;}
cout<<"The Result is: "<<total<<endl;
}
int main()
{
int number1, number2;
for(int i=0;i<3;i++)
{
cout<<"Enter two numbers, where the first is less than the second number "<<endl;
cout<<"Enter the first number: ";
cin>>number1;
cout<<"Enter the second number: ";
cin>>number2;
cin.get();
sumsquares(number1, number2);
cout<<"\n";
}
system("pause");
return 0;
}