Lover Game, Remember Names

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 177
Reputation: Black Magic is an unknown quantity at this point 
Solved Threads: 4
Black Magic's Avatar
Black Magic Black Magic is offline Offline
Junior Poster

Lover Game, Remember Names

 
0
  #1
Apr 24th, 2008
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?

  1. #include <iostream>
  2. #include <conio.h>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. char firstLover[20];
  10. char secondLover[20];
  11.  
  12. unsigned int lovePercent;
  13.  
  14. cout << "Enter The First Lovers Name: ";
  15. cin >> firstLover;
  16.  
  17. cout << endl << "Enter The Second Lovers Name: ";
  18. cin >> secondLover;
  19.  
  20. srand ( time(NULL) );
  21.  
  22. lovePercent = rand() % 100 + 1;
  23.  
  24. cout << endl << "Your Love Percentage Is : " << lovePercent << "%!";
  25.  
  26. getch();
  27. }

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
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 248
Reputation: hammerhead is an unknown quantity at this point 
Solved Threads: 24
hammerhead's Avatar
hammerhead hammerhead is offline Offline
Posting Whiz in Training

Re: Lover Game, Remember Names

 
0
  #2
Apr 24th, 2008
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.
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 177
Reputation: Black Magic is an unknown quantity at this point 
Solved Threads: 4
Black Magic's Avatar
Black Magic Black Magic is offline Offline
Junior Poster

Re: Lover Game, Remember Names

 
0
  #3
Apr 24th, 2008
I get you, but not how to do that,

Could you please post a little example and then i would work on it from that

Thank you!
C Plus Plus Coder.
Fourteen Years Of Age
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,297
Reputation: majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about 
Solved Threads: 68
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Nearly a Posting Virtuoso

Re: Lover Game, Remember Names

 
0
  #4
Apr 24th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 248
Reputation: hammerhead is an unknown quantity at this point 
Solved Threads: 24
hammerhead's Avatar
hammerhead hammerhead is offline Offline
Posting Whiz in Training

Re: Lover Game, Remember Names

 
1
  #5
Apr 24th, 2008
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.
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,297
Reputation: majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about majestic0110 has a spectacular aura about 
Solved Threads: 68
majestic0110's Avatar
majestic0110 majestic0110 is offline Offline
Nearly a Posting Virtuoso

Re: Lover Game, Remember Names

 
0
  #6
Apr 24th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 177
Reputation: Black Magic is an unknown quantity at this point 
Solved Threads: 4
Black Magic's Avatar
Black Magic Black Magic is offline Offline
Junior Poster

Re: Lover Game, Remember Names

 
0
  #7
Apr 24th, 2008
i like hammers idea but i think im going to go for maj's solution, how would i save the names to file? i know how to write like this is a line etc, would i just do that? oh and how would i pair the two names tomorrow?
C Plus Plus Coder.
Fourteen Years Of Age
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 248
Reputation: hammerhead is an unknown quantity at this point 
Solved Threads: 24
hammerhead's Avatar
hammerhead hammerhead is offline Offline
Posting Whiz in Training

Re: Lover Game, Remember Names

 
0
  #8
Apr 24th, 2008
@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
  1. if(result==5)
  2. {
  3. lovePercent=rand()%100+70;
  4. }
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.
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 177
Reputation: Black Magic is an unknown quantity at this point 
Solved Threads: 4
Black Magic's Avatar
Black Magic Black Magic is offline Offline
Junior Poster

Re: Lover Game, Remember Names

 
0
  #9
Apr 24th, 2008
ok, thank you, ive decided to do whitch ever strategy is most effecdent, so would it be hammers idea?
C Plus Plus Coder.
Fourteen Years Of Age
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 35
Reputation: tymk is an unknown quantity at this point 
Solved Threads: 7
tymk tymk is offline Offline
Light Poster

Re: Lover Game, Remember Names

 
0
  #10
Apr 24th, 2008
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.

  1. unsigned int LetterToInt(char letter)
  2. {
  3. unsigned int i = (unsigned int)letter;
  4. if (i >= 65 && i <= 90)
  5. {
  6. i += 32;
  7. }
  8. return i;
  9. }
  10.  
  11. unsigned int NameToInt(char* name)
  12. {
  13. int i = 0;
  14. unsigned int j = 0;
  15.  
  16. while (name[i] != 0)
  17. {
  18. j += (LetterToInt(name[i]) * (i+1));
  19. i++;
  20. }
  21. return j;
  22. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1637 | Replies: 15
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC