:) guys im a firt timer. im making a program which reads floating point numbers from cin and compute 2 averages: the average of the positive and negative nos. im wonderin wats wrong in my program>>

int size,i,sumpos,sumneg;
int num;

cout<<"input size\n";
cin>> size;
for (i=1; i<=size; i++)
cin>> num;
for (i=1; i<=size;i++)
if (num>=0)
else if
sumpos=sumpos/countpos; cout<< ave.pos;
aveneg=sumneg/countneg; cout<<aver.neg;
return 0;

Recommended Answers

what errors do you get?

Jump to Post

All 4 Replies

what errors do you get?

#include <iostream>
using namespace std;
int main()
   int size;
   double num[100];
   double sumpos = 0;
   double sumneg = 0;
   int counterPos = 0;
   int counterNeg = 0;
   cout << "input size:";
   cin >> size;
   for ( int i = 1; i <= size; i++ )
      cin >> num[i];
   for ( int i = 1; i <= size; i++ )
      if ( num[i] >= 0 )
         sumpos = sumpos + num[i];
         sumneg = sumneg + num[i];
   cout << " ave pos " << sumpos / counterPos << endl;
   cout << " ave neg " << sumneg / counterNeg << endl;
   return 0;

Look at your array declaration.(int num, what that means???You must initialize the array with its size) Ensure that the "size" variable should less or equal than the array size and start your loop 0 < size instead 1 <= size so when the user enters the array's size for size variable you will be able to deposit all of them in the array...(And you will guarantee that the user can't get over the array's size because the array's last members's index is array not array)

tnanks a lot

Be a part of the DaniWeb community

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