how to display symbols?

This is a discussion on how to display symbols? within the C++ Programming forums, part of the General Programming Boards category; i have a fruit machine in the console window, and it works ok its just the fact that it prints ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    84

    Question how to display symbols?

    i have a fruit machine in the console window, and it works ok its just the fact that it prints out random numbers.

    the random numbers generated correspond to a fruit machine symbol, and i want a way to print out the symbol and not the number.

    the numbers mean the following -

    1,2,3,4 = cherry
    5,6,7 = melon
    8,9 = lemon
    10 = jackpot

    how can i get this to work?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    I guess this is a console app?
    Well, there are no symbols for those fruits you're asking for in the standard ASCII (as far as I know).
    Take a look at www.asciitable.com and find the characters that matches best, then make a lookup-table:
    Code:
    char Lookup[] = {
    'c', 'c', 'c', 'c', 'm', 'm', 'm', 157, 157, 'J'};
    Use ascii values if it's an 'unprintable' character (special character).
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    84
    yes it is a console application. i don't want symbols in a libary printed or anything.

    i have the symbols set to a number value, and i have a random number generator which generates a number between the vaules which are the fruits.

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    int RandomNumber = rand() % 10;
    cout << Lookup[RandomNumber];
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    33
    Originally posted by Magos
    Code:
    int RandomNumber = rand() % 10;
    cout << Lookup[RandomNumber];
    int RandomNumber = (rand() % 10) +1;
    cout << Lookup[RandomNumber];

    just a little picky sorry:-p

    -Bill

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Array indices start at 0, not 1. Your code would generate a number from 1 to 10, meaning if 10 is generated you would acccess outside the array and may cause an access violation error.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    Registered User
    Join Date
    May 2002
    Posts
    84
    how do i get the cout<<lookup[random] to workl then?

    i'm guessing that its array that the values are in. but how do i get it to work, and where do i need to put the relevent code?

  8. #8
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    have an array of strings (if thats even possible?), and then just have lookup[1, 2, 3, 4] be cherry, and so on and so forth.

  9. #9
    Registered User
    Join Date
    May 2002
    Posts
    84
    i think u can have an array of strings, thats if my memory from the lectures is ok.

  10. #10
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    ok so basically just have

    Code:
    string Lookup[11];
    
    for (int i = 1; i <= 4; i++)
         strcpy (Lookup[i], "Cherry");
    
    for (i = 5; i <= 7; i++)
         strcpy (Lookup[i], "Melon");
    
    strcpy (Lookup[8], "Lemon");
    strcpy (Lookup[9], "Lemon");
    strcpy (Lookup[10], "Jackpot");

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. Trouble with Windows/DirectX programming
    By bobbelPoP in forum Windows Programming
    Replies: 16
    Last Post: 07-08-2008, 03:27 AM
  3. new problem with class
    By jrb47 in forum C++ Programming
    Replies: 0
    Last Post: 12-01-2006, 08:39 AM
  4. Strange error?
    By MrLucky in forum C++ Programming
    Replies: 5
    Last Post: 02-04-2006, 03:01 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

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