Okay here's what I'm trying to do use a for loop get 5 numbers from input ONE number at a time. Output the sum and average of the 5 numbers.

I am only allowed to use a maximum of 2 variables to solve this problem. Heres my code so far, please help me to find error? it compiles but doesnt compute

#include <iostream>
using namespace std;
int main()
{
int startNum;
int nextNum;

	cout<<"Please Input a number " <<endl;
	cin >> startNum;


for(startNum=0; startNum + nextNum<=5; nextNum++)
{
	cout<< startNum+nextNum+nextNum+nextNum+nextNum<< " is the sum of all numbers " <<endl;
	cout<<endl;
	cout<< startNum+nextNum+nextNum+nextNum+nextNum/5 << "is the avg of your numbers " <<endl;
}
	return 0;
}

Any help is appreciated!!

Shouldn't you be prompting, for the numbers, inside the for loop?

I've edited code to say this, however it does not allow user to enter 4 more numbers after original input, what am i doing wrong

#include <iostream>
using namespace std;
int main()
{
int startNum;


	cout<<"Please Input a number " <<endl;
	cin >> startNum;

int nextNum;
nextNum=startNum;
for(startNum=0; startNum + nextNum<=5; nextNum++);
{
	cout<< startNum+nextNum+nextNum+nextNum+nextNum<< " is the sum of all numbers " <<endl;
	cout<<endl;
	cout<< (startNum+nextNum+nextNum+nextNum+nextNum)/5 << "is the avg of your numbers " <<endl;
}
	return 0;
}

Shouldn't you be prompting, for the numbers, inside the for loop?

gerald thanks for your help so far, I've changed code to following but still wont allow user to input 4 more numbers what am i doign wrong?

#include <iostream>
using namespace std;
int main()
{
int startNum;


	cout<<"Please Input a number " <<endl;
	cin >> startNum;

int nextNum;
nextNum=startNum;
for(startNum=0; startNum + nextNum<=5; nextNum++);
{
	cout<< startNum+nextNum+nextNum+nextNum+nextNum<< " is the sum of all numbers " <<endl;
	cout<<endl;
	cout<< (startNum+nextNum+nextNum+nextNum+nextNum)/5 << "is the avg of your numbers " <<endl;
}
	return 0;
}

Maybe you should reread what Gerard said. He's onto something.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.