| | |
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
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg simple sorting string strings template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





