Word :    Username :           
 

ok here is my problem....


Write a program that allows the user to enter values and
prints out the average of all the positive values and the average of all the negative
values entered. Use 0 as the sentinel value.


my code is that::

Code :
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.                 int  number, pos = 0, neg = 0,sum2=0;
  6.                 int  countNEG=0, sum1=0,  countPOS=0;       
  7.                 double averagePOS;   
  8.                 double averageNEG;
  9.                  
  10.                   cout << "nnNumber: ";
  11.                   cin >> number;
  12.                   while (number != 0)
  13.                         {
  14.                               if (number > 0)
  15.                               pos++;
  16.                                           else
  17.                               neg++;
  18.                 sum1 += pos++;
  19.                 countPOS++;
  20.                 sum2 += neg++;
  21.                 countNEG++;
  22.                 cout << "Number: ";
  23.                   cin >> number;
  24.                     }
  25.                   if ( (countPOS == 0) || (countNEG ==0))
  26.                 cout<<"You didn't enter any integer!";
  27.                                                       else
  28.               averagePOS = ((double)sum1) / countPOS;
  29.               averageNEG = ((double)sum2) / countNEG;
  30.              
  31.               cout<<" ";
  32.               cout<<"You entered  "<<countPOS<< " positive integers."<<endl;
  33.               cout<<"You entered  "<<countNEG<< " negative integers."<<endl;           
  34.               cout<<"The average Of positive numbers is  "<<averagePOS<<endl;
  35.               cout<<"The average Of negative numbers is  "<<averageNEG<<endl;
  36.          
  37. cin>>pos;
  38. return 0;
  39. }





help me...... it's wear because i set the positive numbers end the negatives
but always take all numbers.......


also i have this...... problem

Write a program to find the sum of the first 100 terms of the
series:

(1/1* 2) + (1/2* 3) + (1/3* 4) +....+ (1/n * (n + 1))

my code it's not full but i write anything i know,,
i thing is all wrong but anyway i will post it.....



Code :
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.           int number = 1, total = 0,power=1;
  6.           while (power <= 100)
  7.           {
  8.             total = total + number * power;
  9.             power+=power+1;
  10.             number++;
  11.           }
  12. cout << "Total: " <<total;
  13. cin>>total;
  14. return 0;
  15. }
  16. //Mt results here it's 621

Sponsored Links
Register or log in to remove.

yeaup it's easy if you practice ........ so

the solution for the first one is here............ when i found the second i will post, if any one knows something
please help..... thank you!!!!!!

Code :
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.             int number, pos = 0, neg = 0,sum2=0,sum1=0;
  6.             float averagePOS,averageNEG;   
  7.             cout << "Number: ";
  8.             cin >> number;
  9.             while (number != 0)
  10.             { //While loop
  11.               if (number > 0)
  12.             { // IF
  13.               sum1=sum1+number;
  14.               pos++;
  15.               } // END IF
  16.             if (number<0)
  17.             { // IF
  18.             sum2=sum2+number;
  19.             neg++;
  20.             } //END IF
  21.             cout << "Number: ";
  22.             cin >> number;
  23. } //END While loop
  24. averagePOS =  static_cast<float>(sum1)/pos;
  25. averageNEG =  static_cast<float>(sum2)/neg;
  26. cout<<"You entered  "<<pos<< " positive integers."<<endl;
  27. cout<<"You entered  "<<neg<< " negative integers."<<endl;
  28. cout<<"------------------------------------------"<<endl ;         
  29. cout<<"The average Of positive numbers is  "<<averagePOS<<endl;
  30. cout<<"The average Of negative numbers is  "<<averageNEG<<endl;
  31.          
  32. cin>>pos;
  33. return 0;
  34. } ///END cpp.

Reply to ploutarchos
Tom's Hardware > Forum > Applications > Programming > C++ problem
Go to:

There are 859 identified and unidentified users. To see the list of identified users, Click here.

Please mind

You are about to answer a thread that has been inactive for more than 6 months.
If you still wish to proceed, please ensure that your posting is original and does not duplicate or overlap any prior responses to this thread.

Add a reply Cancel
Sponsored links
  • Ask the community now
  • Publish
Ad
They won a badge
Join us in greeting them