Thread: Points saved

  1. #1
    Registered User wayko's Avatar
    Join Date
    Sep 2001
    Posts
    28

    Question Points saved

    is there a way to store points a person earnd on a game?


    #include <iostream.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <fstream.h>


    int main ()
    {
    srand((unsigned)time(0));

    char name[9000];
    int guess;
    const int temp = 1 + (rand()%100);
    int trys = 0;
    int points = 9;
    cout << "Guess what number I am thinking of between 1 and 100...\nto get points you have to guess it in 9 guesses : ";
    cin >> guess;
    while (guess != temp)

    {

    while (guess < temp)
    {
    cout << "The number is higher...Guess again : ";
    cin >> guess;
    trys++; if (trys == 8) {cout << "No points awarded";exit(1);}
    }
    while (guess > temp)
    {
    cout << "The number is lower...Guess again : ";
    cin >> guess;
    trys++; if (trys == 8) {cout << "No points awarded";exit(1);}
    }
    while (guess == temp)


    {
    cout << "You are correct \n and it only took "<<trys+1<<" try(s)...You get 10 points...\nEnter your name :";
    cin >> name;
    break;
    }

    ofstream fout;
    fout.open("testfile.txt");
    fout << "GOOD WORK " << name << " YOU GOT " << points++ << " POINTS";
    fout.close();

    }
    return 0;
    }

    what i am trying to do is a person guess the correct answer then they enter their name and get 10 points and every time they answer correctly they get 10 more ect ect.....
    is there a way to save it on a txt file and the txt file changes as the points increase....?
    hello its me Wayko

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    22
    You would have to create a file that you can read into a linked list. Then you would have to implement a search function for your linked list to search for existing names, then you would have to write the linked list to a file, overwriting the previous one.
    <^>( * ; * )<^>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help it won't compile!!!!!
    By esbo in forum C Programming
    Replies: 58
    Last Post: 01-04-2009, 03:22 PM
  2. Replies: 8
    Last Post: 11-03-2008, 09:48 PM
  3. Replies: 1
    Last Post: 11-27-2007, 07:41 AM
  4. Yahtzee C++ programme help
    By kenneth_888 in forum C++ Programming
    Replies: 13
    Last Post: 09-05-2007, 02:14 PM
  5. CProg Fantasy Football version pi
    By Govtcheez in forum A Brief History of Cprogramming.com
    Replies: 155
    Last Post: 12-26-2006, 04:30 PM