Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Count positive and negative numbers and compute the average of numbers) Write a program that reads an unspecified number of integers, determines how many positive

(Count positive and negative numbers and compute the average of numbers) Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number. If you entire input is 0, display 'No numbers are entered except 0.'

*So I think my code is looping because the compiler says it takes too long. Could I have someone take a look at my code. Thanks!

#include using namespace std;

int main() { int numberOfPositives = 0, numberOfNegatives = 0, total = 0, count = 0; int number; float average;

cout << "Enter an integer: "; cin >> number;

while (number != 0) { total += number; count++;

if (number > 0) { numberOfPositives++; }

else if (number < 0) { numberOfNegatives++; }

else if (total = 0) { cout << "No numbers are entered except 0."; } average = total / count; } cout << "The number of positives is " << numberOfPositives; cout << "The number of negatives is " << numberOfNegatives; cout << "The total is " << total; cout << "The average is " << average; return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions