You are here:

C++/test scores


Hi Rai:

how do can you write a program to read an unknown number of interger test scores from the keyboard(assume at most 150 scores). print the orgininal list of scores, the scores are sorted from low to high, the scores sorted from high to low, the highest score, the lowest score, and the average score

 Here is the skeleton for that. It would help you in sorting. For getting the average, you can add all the elements and divide the sum by the count. This you can do well before the sorting. Sorting can be done in the opposite way if you change the condition in the commented line in the code.:

#include <iostream>
#include <vector>
#include <iterator>

using namespace std;

int main()
  vector <int> Arr;
  char Opt = 1;
  while (Opt)
     int x;
     cout << "enter the number" << endl;
     cin >> x;
     cout << "if you want to enter more number press 1 else 0" << endl;
     cin >> Opt;
     if (!Opt)
  vector::iterator Iter=Arr.begin();
  vector::iterator temp;
  for (; Iter != Arr.end(); ++Iter)
     for (temp = Iter; temp != Arr.end; temp++ )
        // if *temp is > than *Iter, swap them
  return 0;


All Answers

Answers by Expert:

Ask Experts


Dharmender Rai


I can answer general and system level C/C++ questions.


I have 5 years of experience in C++.

©2017 All rights reserved.