Write a Program that asks the user to input a positive integer. If the user inputs a negative number, program should output "ERROR" and ask for /the user's input again. If the user inputs the value of 0, the program says "NO AVERAGE". If the user inputs a -1, the program takes the sum and average of only the positive integers, then outputs "The average is _____ "

I dont understand what I'm doing wrong

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;

int main()
int number;
double sum, average;
cout<<"Type Positive Integers: ";
cin>> number;
sum += number;
average = sum/=number;

    cout<<"Type Positive Integers: ";
    cout<<"NO AVERAGE: ";
        cout<<"ERROR!"<< "Enter Another Value: ";
        cin>> number;
    if(number== -1){
        cout<<"The Average of the Positive Integers is :"<< average << endl;
Re: C++ Assignment and I am stuck 80 80

How about changing line 19 to test for not equal -1 (your exit condition)?

And drop line 27 since you will loop around to line 21 for another input.

While this current code omits counting how many valid numbers were input, you can start by fixing up a few basic things then add your input counter later.

Re: C++ Assignment and I am stuck 80 80

Your specs don't make sense. A negative number results in ERROR but -1 performs an action. Last I checked, -1 was a negative number. Do we take the spec from your text or from your code? They can't both be correct.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.