High Score Not Working...

This is a discussion on High Score Not Working... within the C++ Programming forums, part of the General Programming Boards category; Why doesn't the highscore function work? It always accepts your name even if it is lower....And How do I make ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    3

    High Score Not Working...

    Why doesn't the highscore function work? It always accepts your name even if it is lower....And How do I make it so that high[4] and high [5] together equals the high score? I tried high[4,5] along with other things..,Thanks!

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <fstream>
    #include <ctime>
    
    
    using namespace std;
    
    int main()
    {
      srand(time(NULL));
      int number;
      int percent = 10;
      int fav = 1 + (rand()%percent);
      int again;
      int input;
      int turns = 0;
      int rounds = 0;
      char high[7];
      int highscorenumber;
      char initials[3];
        
        ifstream readscore ("high.txt");
        readscore.getline(high,7);
        <<high[4] high[5]<< = highscorenumber;
        cout<<"See if you can guess the number! You get 6 turns per round!\n Every round you complete it gets tougher!";
        cin.get();
        system("cls");
        do{                   //Main Game Loop
        cout<<"\n\nEnter a number!!!";
        cin>> number; //Gets number
        cin.ignore();
        while (number != fav){//Do while the number isn't equal to  Favorite
        if (number < fav && turns < 6)
             {
                        turns = turns + 1;
                        system("cls");
                        cout<<"| Turns || Rounds || Last Guess |";
                        cout<<"\n|  "<<turns<<"    ||    "<<rounds<<"   ||      "<<number<<"     |";
                        cout<<"\n---------------------------------";
                        cout<<"\n\nWRONG! Try guessing Higher\n";
                         cout<<"Enter New Number...\n";
                     cin>> number;  //Tells wrongs and to guess a higher number
                        }
        
        else if (number > fav && turns < 6) {
                    turns = turns + 1;
                    system("cls");
                                cout<<"| Turns || Rounds || Last Guess |";
        cout<<"\n|  "<<turns<<"    ||    "<<rounds<<"   ||      "<<number<<"     |";
            cout<<"\n---------------------------------";
                     cout<<"\n\nWRONG!!! Try guessing Lower...\n";
                     cout<<"Enter New Number...\n";
                     cin>> number;
                     
             }
             
        else if (turns == 6) {
                          cout<<"WRONG!! Game Over!\n\nThe number was "<<fav<<"";
                          cout<<"\nYou played " <<rounds<< " rounds!\n";
                                       if (highscorenumber < rounds) {
                                                                        cout<<"You got A High Score!";
                                                                        cout<<"Enter your Initials! Enter 3! If you have 2 just add a space to the end!";
                                                                        cin>>initials;
                                                                        ofstream highscore ("high.txt");
                                                                        highscore << initials <<"-" <<rounds<< endl;
                                                                        cout<<"Thanks For Playing!";
                                                                        cin.get();
                                                                        return 0;
                                                                        }
                                       else {
                                                      cin.get();
                                                      cin.get();
                                                      return 0;
                                                      }
             
             }
             }
             rounds = rounds+1;
             turns = turns - turns;
             cout<<"CORRECT!!!\n";
             cout<<"Do you want to go to the next round? 1 for Yes/2 for No\n";
             cin>> input;
             cin.ignore();
              switch(input){
                     case 1:
                          percent= percent + 10;
                          fav = 1 + (rand()%percent);
                          again=1;
                          system("cls");
                          break;
                     default:
                          again=0;
                          cout<<"You played " <<rounds<< " rounds!\n";
                          if (highscorenumber < rounds) {
                                                                        cout<<"You got A High Score!";
                                                                        cout<<"Enter your Initials! Enter 3 Letters!\nIf you have 2 just add a space to the end!";
                                                                        cin>>initials;
                                                                        ofstream highscore ("high.txt");
                                                                        highscore << initials <<"-" <<rounds<< endl;
                                                                        cout<<"Thanks For Playing!";
                                                                        cin.get();
                                                                        return 0;
                                                                        }
                                       else {
                          cin.get();
                          cout<<"\nGame Over!";
                          cin.get();
                          return 0;
                          break;
                          }
                          }
             }while (again == 1);
    
    return 0;
    }

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    try cutting out to exactly where your problem is. if by the second part of your question you mean you want to add the two numbers, you do it like this:

    Code:
    highScore=score[4]+score[5];
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    3
    Not add...But like...append almost...

    So if high[4] was 1 and high[5] was 2

    The total highscore would be 12

  4. #4
    Banned
    Join Date
    Oct 2004
    Posts
    250
    Thats what major_smalls code does 'highScore=score[4]+score[5];' basically means assign highscore the value of score[4]+score[5].

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    3
    Oh...Sorry...I thought it added the two together like 1+2 =3

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  2. LISP (DrScheme) any one?
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-31-2004, 11:52 AM
  3. High Scores
    By Gnoober in forum C++ Programming
    Replies: 2
    Last Post: 02-13-2003, 12:08 PM
  4. High score question
    By Magriep in forum Game Programming
    Replies: 5
    Last Post: 02-27-2002, 09:36 AM
  5. High Score Table
    By GaPe in forum C Programming
    Replies: 8
    Last Post: 12-13-2001, 11:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21