| | |
Lover Game, Remember Names
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Hey,
I was just mucking around and made a simple random number generator and made a "love percentage game" but, if you re-open the .exe and type the same names in it gives another completely different percentage, would i save the names to do a file or some kind?
Please reply with help, A.S.A.P
I was just mucking around and made a simple random number generator and made a "love percentage game" but, if you re-open the .exe and type the same names in it gives another completely different percentage, would i save the names to do a file or some kind?
c++ Syntax (Toggle Plain Text)
#include <iostream> #include <conio.h> #include <time.h> using namespace std; int main() { char firstLover[20]; char secondLover[20]; unsigned int lovePercent; cout << "Enter The First Lovers Name: "; cin >> firstLover; cout << endl << "Enter The Second Lovers Name: "; cin >> secondLover; srand ( time(NULL) ); lovePercent = rand() % 100 + 1; cout << endl << "Your Love Percentage Is : " << lovePercent << "%!"; getch(); }
Please reply with help, A.S.A.P
Last edited by Black Magic; Apr 24th, 2008 at 4:43 pm.
C Plus Plus Coder.
Fourteen Years Of Age
Fourteen Years Of Age
The program is correct. There is no relation between the names and the love percentage and thus the program only displays random numbers between 0 to 100.
You may want to use some relationship between names and random number generation in order to get a similar percentage for a given set of names.
You may want to use some relationship between names and random number generation in order to get a similar percentage for a given set of names.
There are 10 types of people in the world, those who understand binary and those who don't.
All generalizations are wrong. Even this one.
All generalizations are wrong. Even this one.
I guess that you could store the results in an external text file, then when two matching names are entered, check if they exist on that text file and then print out a corresponding score for that pair. Of course, the pairs are not stored in the text file until after they have been entered into the game at least once. This method seems a little 'clunky' though so maybe someone might come up with something better. Hope this helps!
Computers are man's attempt at designing a cat: It does whatever it wants, whenever it wants, and rarely ever at the right time.
That depends on how you want the love percentage to be calculated and if you want it to be the same for a given set of names. For example you can say that the love percentage will be higher if the two names are similar.
Now you can define 'similar' in your own manner, for example two names can be similar if
1. They have the same length or
2. They have same vowels or
3. Their edit distance is minimum
etc etc. After that you can threshold or use a formula to relate probability to the names. For example if the difference in length of the names is 2 then percentage will be between 0-30, if it is 1 then it will be between 30-60 and if the length is same then the percentage will be between 60-100.
Now you can define 'similar' in your own manner, for example two names can be similar if
1. They have the same length or
2. They have same vowels or
3. Their edit distance is minimum
etc etc. After that you can threshold or use a formula to relate probability to the names. For example if the difference in length of the names is 2 then percentage will be between 0-30, if it is 1 then it will be between 30-60 and if the length is same then the percentage will be between 60-100.
Last edited by hammerhead; Apr 24th, 2008 at 5:12 pm.
There are 10 types of people in the world, those who understand binary and those who don't.
All generalizations are wrong. Even this one.
All generalizations are wrong. Even this one.
That is a very good idea Hammerhead, only trouble is that it is not truly random if there are formulas involved but that might not matter to OP. Nice plan, that approach did not occur to me!
Computers are man's attempt at designing a cat: It does whatever it wants, whenever it wants, and rarely ever at the right time.
@majestic0110
Random numbers come after applying the formula, it is however only to fool the end user
. Lets say for example that I get result as '5' after application of the formula. Now I can use
by doing so I will still get variable percentage. I can make similar cases for result==4,3,2 and so on.
@Black Magic
My file handling is weak, but you can make a structure of two strings(names) and then use read(), write() functions of fstream to read/write the structure. I suggest you to wait for someone more experienced to reply.
Random numbers come after applying the formula, it is however only to fool the end user
. Lets say for example that I get result as '5' after application of the formula. Now I can use C++ Syntax (Toggle Plain Text)
if(result==5) { lovePercent=rand()%100+70; }
@Black Magic
My file handling is weak, but you can make a structure of two strings(names) and then use read(), write() functions of fstream to read/write the structure. I suggest you to wait for someone more experienced to reply.
Last edited by hammerhead; Apr 24th, 2008 at 5:35 pm.
There are 10 types of people in the world, those who understand binary and those who don't.
All generalizations are wrong. Even this one.
All generalizations are wrong. Even this one.
•
•
Join Date: Apr 2008
Posts: 35
Reputation:
Solved Threads: 7
I came up with these helper functions to convert a name to a number. Even with different capitalization, the same name will be the same number each time. You can then add these numbers together and use the result to seed the random number generator or use the numbers in some other way to come up with your percentage.
cpp Syntax (Toggle Plain Text)
unsigned int LetterToInt(char letter) { unsigned int i = (unsigned int)letter; if (i >= 65 && i <= 90) { i += 32; } return i; } unsigned int NameToInt(char* name) { int i = 0; unsigned int j = 0; while (name[i] != 0) { j += (LetterToInt(name[i]) * (i+1)); i++; } return j; }
![]() |
Other Threads in the C++ Forum
- Previous Thread: Error when evaluate some Postfix
- Next Thread: If i was to make a 2 player game what would i use?
Views: 1637 | Replies: 15
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






