By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,847 Members | 2,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,847 IT Pros & Developers. It's quick & easy.

Highscore system

P: 17
Im sitting at home tryin gto learn some c++ form what i can read of the internet, so if some of the code looks familiar its probably from some tutorial out there.

So...I think i got the basic basics down and im trying to move on to dimensonal arrays. I've read about it so i have teh basic idea down.

Im trying to make a highscoresystem and have gotn this far. But i want my arrays to store both an index number, name, and score for the player. How do i do that?

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main (int argc, char** argv)
  7. {
  8.     vector<double> doubleVector(10); //create a vector of 10 doubles
  9.     double max;
  10.     int i;
  11.  
  12.     for (i = 0; i < 10; i++) {
  13.         doubleVector[i] = 0;
  14.      }
  15.  
  16.     //Read the first score before the loop in order to initialize the max
  17.     cout << "Enter score 1: ";
  18.     cin >> doubleVector[0];
  19.     max = doubleVector[0];
  20.  
  21.     for (i = 1; i<10; i++) {
  22.         cout << "Enter score " << i + 1 << ": ";
  23.         cin >> doubleVector[i];
  24.         if (doubleVector[i] > max) {
  25.             max = doubleVector[i];
  26.         }
  27.     }
  28.  
  29.     sort(doubleVector.begin(), doubleVector.end());
  30.  
  31.     for (i = 0; i < 10; i++) {
  32.         cout << doubleVector[i] << " ";
  33.     }
  34.  
  35.     cout << endl;
  36.     return 0;    
  37. }

thanks
Jun 7 '07 #1
Share this Question
Share on Google+
3 Replies


DeMan
100+
P: 1,806
Hi Moezzie ,

Welcome to thescripts. You will find a variety of forums on different topics available through the links on the blue bar near the top of this screen.

I will move this post to the c/c++ forum for you, and hopefully a c/c++ expert will be able to address you query. I hope they can help you with your problem!
Jun 7 '07 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
The only mechanism for grouping data together is a class.

Expand|Select|Wrap|Line Numbers
  1. class Player
  2. {
  3.     private:
  4.        double highscore;
  5.        string name;
  6.     public:
  7.        //write class methods here
  8. };
  9.  
Start here. Learn how to write a class. When that's working, create your Player objects and put them in a C++ Standard Library Container. My guess is that you will want to use a vector.

This should get you going. I don't want to code the whole thing for you.
Jun 7 '07 #3

P: 17
yeah, i just whant a basic idea about how to do it.
That helps alot.
Thanks.
Jun 7 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.