Hi,
I wrote this code to add 10 numbers and find their average. It will not out put average.
What am I doing wrong?

Thanks for the help.

#include <iostream>

using namespace std ;
int main ( )
{
	double Sum;

	double Average;

	double Numbers[10];

	int K;

	Sum = 0;

	Average = 0;

	for ( K = 0; K < 10; K++ )

	{
		cout <<  " Enter Your Numbers " << ( K + 1 ) << endl;
		cin >> Numbers[K];
		Sum = Sum + Numbers[K];
	}
	    Average = Sum/10;
		for ( K = 0; K < 10; K++);

		{
			cout << " The numbers you Entered  are " << Numbers [K] << endl;
		}
		  cout << " The Average of the Numbers is " << Average << endl;
		  return(0);
}

At Line 20 , where it says
cout << "The Numbers you Entered are" << Number [K] i feel something wrong there?

semicolon is added after for loop. remove it.

Thanks, I did. All is ok?

It looks good to me. Did it compile and run properly for you now?

Yes Ty

Hey jashbela,
There is nothing wrong wrong in the average logic. I have compiled it also. The average result is right.

Please refrain from using "leet speak" e.g "ty" and "wit"

Keep it Clear
Do post in full-sentence English
Do not write in all uppercase or use "leet", "txt" or "chatroom" speak

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

 
       double Sum = 0;
  
       
  
       double  Average = 0,Numbers;
  

  for(Numbers=0;Numbers<=10;Numbers++)
  {
      cout << " Enter Your Numbers ";
  
      cin >> Numbers;
  
      Sum = Sum + Numbers;
  
   
  
      Average = Sum/10;
  }
      cout << " The numbers you Entered are " << Numbers<< endl;
  
      cout << " The Average of the Numbers is " << Average << endl;
 
  
      return(0);
  
      }

// just take a look of mt simple program/// nice day

Member Avatar for HASHMI007

Hi,
I wrote this code to add 10 numbers and find their average. It will not out put average.
What am I doing wrong?

Thanks for the help.

for ( K = 0; K < 10; K++);

		{
			cout << " The numbers you Entered  are " << Numbers [K] << endl;
		}

Mistake at that point in line 21

No Need To Use
<<( K + 1 ) << endl;
When You Getting The Number

I think your code will be from line 18 to 24.

for ( K = 0; K < 10; K++ )
cout << " Enter Your Numbers "  ;
for ( K = 0; K < 10; K++ )
{
cin >> Numbers[K];
Sum = Sum + Numbers[K];
}
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.