You are viewing our Forum Archives. To view or take place in current topics click here.
Someone good with C++ Help please!
Posted:
Someone good with C++ Help please!Posted:
Status: Offline
Joined: Jul 01, 201013Year Member
Posts: 500
Reputation Power: 23
The Exercise
Consider the following code:
Your task is to rewrite this program so that it performs exactly the same task but has a main
function that must look exactly like the following:
Could someone please help me with this?
I've been trying for hours, im new to c++ and just need some help.
Consider the following code:
#include <iostream>
using namespace std;
int main()
{
int low;
int high;
cout << "Enter a value:";
cin >> low;
cout << "Enter a value:";
cin >> high;
cout << "Thank you for the input!" << endl;
int sum=0;
for(int i=low; i<=high; i++)
sum+=i*i;
cout << "The sum from i=" << low << " to " << high << " of i^2 is :"
<< sum << endl;
return 0;
}
Your task is to rewrite this program so that it performs exactly the same task but has a main
function that must look exactly like the following:
int main()
{
int low=get_value();
int high=get_value();
cout << "Thank you for the input!" << endl;
cout << "the sum from i=" << low << " to " << high << " of i^2 is :"
<< sumi2(low,high) << endl;
return 0;
}
Could someone please help me with this?
I've been trying for hours, im new to c++ and just need some help.
#2. Posted:
Status: Offline
Joined: Jul 12, 201013Year Member
Posts: 2,684
Reputation Power: 122
Status: Offline
Joined: Jul 12, 201013Year Member
Posts: 2,684
Reputation Power: 122
Whoever set you this task is a **** moron. They're asking you to use cin inside a function which would result in an inflexible and DOS-only program.
However this is probably what they're looking for
However this is probably what they're looking for
int get_value() {
cin >> input;
return input;
}
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.