answersLogoWhite

0


Best Answer

#include <iostream>

#include <cstdlib>

using namespace std;

int main()

{

int count =0;

int sum = 0;

int positivecount = 0;

int negativecount = 0;

double average;

cout <<"Enter any integer or enter 0 to exit ::";

cin >> count;

while(count != 0)

{

sum += count;

average = sum / static_cast<double>(count);

count++;

if(count < 0)

{

negativecount++;

}

if (count > 0)

{

positivecount++;

}

cout <<"Enter any integer or enter 0 to exit ::";

cin >> count;

}

cout <<"the average of the numbers is " << average <<"\n";

cout <<"There are " << negativecount <<" negative numbers\n";

cout <<"There are " << positivecount<<" positive numbers\n";

system("pause");

return 0;

}

by rijaalu

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

//to count no. of +ve,-ve and 0s
#include
main()
{
int a[100],p=0,n=0,z=0,m,i;
printf("enter the nth no:\n");
scanf("%d",&m);
for(i=1;i<=m;i++)
{
printf("enter %d\n",i);
scanf("%d",&a[i]);
}
for(i=1;i<=m;i++)
{
if(a[i]==0)
z++;
else if(a[i]>0)
p++;
else
n++;
}
printf("positive=%d \n Negative= %d \n Zeroes= %d \n",p,n,z);

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

So, I'm guessing you need to assume that you need to assign enough space in the array so that you can have a logical number of whatever you are storing. Use common since on this one; you wont need to allocate a 2000 index array when asking how many numbers need to be read in. So you can just use the assigned array spaces and forget about the rest. Here is an example that read in the data and does a little something different but you can change the display scores method to do what you need. Hope this helps!

import java.util.Scanner;

public class Exercise06_04

{

public static void main(String args[]) {

Scanner input = new Scanner(System.in);

double[] givenScores = new double[10];

double sum = 0;

int count = 0;

while (count <= 10) {

System.out.print("Enter a new score: ");

double givenScore = input.nextDouble();

if (givenScore <= 0){

break;

}

else{

givenScores[count] = givenScore;

sum += givenScores[count];

count++;

}

}

double average = sum/count;

displayScores(givenScores, average, count);

}

public static void displayScores(double[] givenScores, double average, int count) {

int aboveCount = 0, belowCount = 0;

for (int i = 0; i < count; i++) {

if (givenScores[i] >= average)

aboveCount++;

else

belowCount++;

}

System.out.println("Average is " + average);

System.out.println("Number of scores above or equal to the average " + aboveCount);

System.out.println("Number of scores below the average " + belowCount);

}

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to enter the numbers till the user wants and at the end it should display the count of positive and negative and zeros entered?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the relationship between neggative positive and positive negative?

Negative number and positive numbers are all numbers. Negative numbers are just positive numbers multiplied by -1.


When multiplying numbers what do you do with the positive and negative signs?

Negative * positive = negative Positive * positive = positive Negative * negative = positive


What is the sign of the product of 47 negative numbers and three positive numbers?

Negative because product of 47 negative numbers is negative and product of three positive number is Positive , so negative*positive = Negative.


Is the product of 33 negative numbers and 2 positive numbers a positive number or a negative number?

(The product of 33 negative numbers) x (2 positive numbers) = (negative sign) x (positive sign) = negative sign


Is the product of positive numbers and 7 negative numbers a positive number or a negative number?

negative


Is the product of 7 positive numbers and 6 negative numbers a positive or negative number?

positive


What are the rules for multiplying integers?

Positive x Positive =Positive Positive x Negative= Negative Negative x Positive= Negative Negative x Negative =Positive


Why are negative numbers in brackets positive but positive numbers in brackets are not negative?

'cuz


What is the product of two negative and three positive numbers?

It is positive. Any product of an even number of negative numbers will be positive, regardless of how many positive numbers you have. Similarly any product of an odd number of negative numbers will be negative, regardless of how many positive numbers you have.


Where can you find positive and negative numbers in your house?

Positive numbers, on your door. Negative in your freezer.


Are positive and negative numbers integers?

yes integers are all numbers negative and positive


Are negative numbers bigger or positive?

Positive numbers are larger than negative ones.