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;
}

Edited 6 Years Ago by cortez716: n/a

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;
}
This article has been dead for over six months. Start a new discussion instead.