Algorithms and Programming Lesson Lab 4

beykent logo ile ilgili görsel sonucu

QUESTION 9
Write a program that reads in ten whole numbers and that outputs the sum of all the numbers greater that zero,the sum of all the numbers less than zero(which will be a negative number of zero) , and the sum of all the numbers, whether positive, negative, or zero.The user enters the ten numbers just once each and the user to enter the positive numbers and the negative numbers separately.

ANSWER;

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main(){


int usersNumber;
int sumOfNumber = 0;
int sumOfPositiveNumber = 0;
int sumOfNegativeNumber = 0;
int counter = 1;


 while(counter<11){
cout << "Write a number: " << endl;
cin >> usersNumber;
counter++;
if(usersNumber<0){
sumOfNegativeNumber = sumOfNegativeNumber + usersNumber;
}
else {
sumOfPositiveNumber = sumOfPositiveNumber + usersNumber;
}
sumOfNumber = sumOfNumber + usersNumber;
}
cout<<endl<<"Sum of Number is :" <<sumOfNumber <<endl;
cout<<"Sum of Positive Number is:" <<sumOfPositiveNumber <<endl;
cout<<"Sum of Negative Number is:" <<sumOfNegativeNumber <<endl;

return 0;

}

Comments

Popular Posts