Write a C++ program to read 20 numbers from user and place them in a one dimensional array. The program should?
-
Write a C++ program to read 20 numbers from user and place them in a one dimensional array. The program should then read from the array and calculate the maximum value the minimum ...show more
-
Answer:
This is your code: //prompt for error if (infile.fail()) cerr << "Error opening input file.\n "; exit(1); // make it: //prompt for error if (infile.fail()) { cerr << "Error opening input file.\n "; exit(1); } In your code the cerr statement was reached conditionally., while the exit(1) statement was reached unconditionally. exit(1) is always executing!!!!
UNONL6D5H5GNTBSY7IJMJNDXU4 at Yahoo! Answers Visit the source
Other answers
you were working too hard... specs called to read from user not a file.... #include <iostream> #include <iomanip> #include <fstream> using namespace std; int main() { double sum,av,smallest,largest; double nums[20]; int count; cout << "enter numbers:"; cin >> nums[0]; sum=smallest=largest=nums[0];// set largest smallest and sum to first element. for(count=1;count<20;count++){ cin >> nums[count]; sum+=nums[count]; if (nums[count]> largest) largest=nums[count]; if(nums[count]<smallest) smallest=nums[count]; } cout << "sum = " << sum << endl; cout << "largest value = " << largest << endl; cout << "smallest value = " << smallest << endl; cout << "Average = " << sum/20. << endl; system("pause"); return 0; }
roger
Related Q & A:
- How to write a parser in C?Best solution by Stack Overflow
- How to write a program to monitor the temperature of CPU?Best solution by Stack Overflow
- How Can I use .net dll in C program?Best solution by Stack Overflow
- How to run an executable from within a c program?Best solution by Stack Overflow
- How to write a TV program proposal?
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.