-
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?
-
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).
-
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.
-
Code:
int RandomNumber = rand() % 10;
cout << Lookup[RandomNumber];
-
Quote:
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
-
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.
-
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?
-
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.
-
i think u can have an array of strings, thats if my memory from the lectures is ok.
-
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");