How to calculate max/min scales on a scatter plot?

What's wrong with my code for the Min, Max and Average in C++?

  • : Min-max Write a program that takes numbers from the user until they type "0". Using conditional statements, track theminimum value, the maximum value and calculate the average. You may only use the following variables for this program - no more than the number given. int n; // keeps track of how many numbers have been input int x; // stores the user input int total; // stores the current running total int minimum; // stores the minimum value int maximum; // stores the maximum value C++ skills: 1. Use variables of the correct type to store temporary values during calculations 2. Use loops to execute a repetitive process 3. Use conditional logic to determine when to stop execution 4. Use relational operators to compare numerical values (>, <, >=, <=, ==, !=) Sample input: 3 8 13 4 1 0 Sample output: Minimum: 1 Maximum: 13 Average: 5.8 # include <iostream> # include <cmath> using namespace std; int main() { int n= 0; int x = 0; double total= 0, average; float min= 100-x; float max=0+x; while (x !=0) cout << "Enter number of integers:" <<n; while (x<n) { cout<<"Enter Numbers:"; cin>>n; if(n<min) min=n-x; if(n>max) max=n; total=x+n; x=x+1; } { cout<<"average is:"<<total/n<<endl; cout<<"minimum number is:"<<min<<endl; cout<<"maximum number is:"<<max<<endl; } }

  • Answer:

    int main() { int n= 0,m; int x = 0; double total= 0, average; float min= 100; float max=0; do { cout << "Enter number of integers:"; cin>>m; }while(m<=0); while (x<m) { cout<<"Enter a Number:"; cin>>n; if(x==0) { min=n; max=n; } if(n<min) min=n; if(n>max) max=n; total=total+n; x=x+1; } cout<<"average is:"<<(total/m)<<endl; cout<<"minimum number is:"<<min<<endl; cout<<"maximum number is:"<<max<<endl; }

Samah Tahir at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

int main() { int n= 0,m; int x = 0; double total= 0, average; float min= 100; float max=0; do { cout << "Enter number of integers:"; cin>>m; }while(m<=0); while (x<m) { cout<<"Enter a Number:"; cin>>n; if(x==0) { min=n; max=n; } if(n<min) min=n; if(n>max) max=n; total=total+n; x=x+1; } cout<<"average is:"<<(total/m)<<endl; cout<<"minimum number is:"<<min<<endl; cout<<"maximum number is:"<<max<<endl; }

James Bond

Related Q & A:

Just Added Q & A:

Find solution

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.