Hey all, currently i am doing this question
Write a C++ program such that its execution will keep asking the user to enter a pair of integers, start and finish, and will terminate when either start>finish, or EOF or an invalid input has been encountered. Every time a new pair of integers start and finish are read, the program will first calculate the subtotal
start2 + (start+1)2 + (start+2)2 + ... + (finish-1)2 + finish2and then add the subtotal to the total. Before the program terminates, it should display the accumulatedtotal and the average of all the subtotals.
This is the code i have managed to get so get so far
Code:
#include <iostream>#include <cmath>
// #include <string>
using namespace std;
int main()
{
double start, finish, subtotal, total, average;
float a, b, c ;
bool ValidInput = false;
do
{
cout << "Enter the START and FINISH number: ";
cin >> a, b ;
c = pow(a , b);
cout << a << "to the power of " << b << "equals to" << c
<< '_' << endl << endl;
if (cin.fail() || start < finish)
{
cin.clear();
cin.ignore();
return 0;
}
else
{
double total;
total = start + finish;
cout << "The Subtotal Is : " << subtotal << endl;
cout << "The Total Is: " << total << endl;
cout << "The average is: " << average << endl;
}
} while ( ValidInput == false );
system ("pause");
return 0;
}