| | |
C++Help Positive Number Average program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2008
Posts: 6
Reputation:
Solved Threads: 0
This program kinda works, but I have one problem. I setup this program to display a message when someone enters a negative number, but I how do I set the count back to zero. Even though mesage prompts the user that a negative number is invalid, it still calculates the number in the average. Please help
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() { // Variables const int positive_numbers = 10; int numbers[positive_numbers]; double average; double sum = 0.0; int num; //Read all numbers for (int i = 0; i < positive_numbers; i++) { cout << "Enter a number: "; cin >> num; if( num < 0 ) cout << "Invalid! Please enter a number greater than or equal to zero." << endl; numbers[i] = num; sum += numbers[i];[/B] } //Find the average average = sum/10; // Display average cout <<"\nThe average is " << average <<"\n\n"; return 0; }
Last edited by Narue; Sep 4th, 2008 at 1:21 pm. Reason: add
![]() |
Similar Threads
- problem with a java program (Java)
- Loops: The 'any' inquiry (C++)
- I need some help with basic C++ (C++)
- can someone please help me (Computer Science)
- Help with precision (C++)
- Stupid...factorial..lol (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: function cause error!
- Next Thread: recursion
Views: 1152 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete deploy dll download dynamic encryption error file forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number output pointer problem program programming project python random read recursion recursive reference return simple sort spoonfeeding stream string strings struct temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





