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::
[cpp]
#include<iostream>
using namespace std;
int main()
{
int number, pos = 0, neg = 0,sum2=0;
int countNEG=0, sum1=0, countPOS=0;
double averagePOS;
double averageNEG;
cout << "nnNumber: ";
cin >> number;
while (number != 0)
{
if (number > 0)
pos++;
else
neg++;
sum1 += pos++;
countPOS++;
sum2 += neg++;
countNEG++;
cout << "Number: ";
cin >> number;
}
if ( (countPOS == 0) || (countNEG ==0))
cout<<"You didn't enter any integer!";
else
averagePOS = ((double)sum1) / countPOS;
averageNEG = ((double)sum2) / countNEG;
cout<<" ";
cout<<"You entered "<<countPOS<< " positive integers."<<endl;
cout<<"You entered "<<countNEG<< " negative integers."<<endl;
cout<<"The average Of positive numbers is "<<averagePOS<<endl;
cout<<"The average Of negative numbers is "<<averageNEG<<endl;
cin>>pos;
return 0;
}
[/cpp]
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.....
[cpp]#include<iostream>
using namespace std;
int main()
{
int number = 1, total = 0,power=1;
while (power <= 100)
{
total = total + number * power;
power+=power+1;
number++;
}
cout << "Total: " <<total;
cin>>total;
return 0;
}
//Mt results here it's 621
[/cpp]
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::
[cpp]
#include<iostream>
using namespace std;
int main()
{
int number, pos = 0, neg = 0,sum2=0;
int countNEG=0, sum1=0, countPOS=0;
double averagePOS;
double averageNEG;
cout << "nnNumber: ";
cin >> number;
while (number != 0)
{
if (number > 0)
pos++;
else
neg++;
sum1 += pos++;
countPOS++;
sum2 += neg++;
countNEG++;
cout << "Number: ";
cin >> number;
}
if ( (countPOS == 0) || (countNEG ==0))
cout<<"You didn't enter any integer!";
else
averagePOS = ((double)sum1) / countPOS;
averageNEG = ((double)sum2) / countNEG;
cout<<" ";
cout<<"You entered "<<countPOS<< " positive integers."<<endl;
cout<<"You entered "<<countNEG<< " negative integers."<<endl;
cout<<"The average Of positive numbers is "<<averagePOS<<endl;
cout<<"The average Of negative numbers is "<<averageNEG<<endl;
cin>>pos;
return 0;
}
[/cpp]
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.....
[cpp]#include<iostream>
using namespace std;
int main()
{
int number = 1, total = 0,power=1;
while (power <= 100)
{
total = total + number * power;
power+=power+1;
number++;
}
cout << "Total: " <<total;
cin>>total;
return 0;
}
//Mt results here it's 621
[/cpp]