Hi forums, i need someone's help to solve this problem. I am trying to use the random function to generate a four digit numbers and give clues when the user enter a correct digit. I do not know why the digit generated is wrong and the clue given is wrong too. I used the MOD and integer division but it does not solve the problem . Hope that someone can help me find out the problem of my code.
case 2 : while(again1){
cout << "Setting" << endl ;
cout << "*********" << endl ;
cout << "1. Value Range (for each digit) :" << LowerValueRange << " to " << UpperValueRange << "." << endl ;
cout << "2. Maximum Score :" << DefaultMaxScore << "." << endl << endl ;
cout << "If player wish to change the value range, please enter 1." << endl ;
cout << "If player wish to change the maximum score, please enter 2." << endl ;
cout << "If player do not wish to change anything, please enter 3." << endl << endl ;
cout << "Option :" ;
cin >> Setting ;
cout << endl ;
if (Setting ==1){
cout << "PLease enter the lower limit of the value range :" ;
cin >> LowerValueRange ;
cout << "Please enter the upper limit of the value range :" ;
cin >> UpperValueRange ;
LowerValueRange = LowerValueRange ;
UpperValueRange = UpperValueRange ;
cout << endl ;
cout << "The new value range :" << LowerValueRange << " to " << UpperValueRange << endl << endl ;
}
else if (Setting ==2){
cout << "Please enter maximum score :" ;
cin >> MaxScore ;
cout << "The new maximum score :" << MaxScore << endl << endl ;
DefaultMaxScore = MaxScore ;
}
else if (Setting==3) {
again1 = false ;
}
else {
cout << "Invalid Option. Please enter the option again :" << endl << endl ;
#include <cstdlib> #include <stdlib.h> //remove this. its the C version of the one you already had.
it looks like you want the digits but are dealing with it as ints.
if you just read the number as a string, you can look at the characters that represent digits and its a LOT easier to do and cleaner.
I am not sure but I don't think you grok mod.
num % 10 … if num is 1234, this is 4. That works.
num %100 … not so much. this is 34. if you subtracted the above from it and divided by 10, you would get 3....
unless I am totally not seeing what you are trying to do.
To All :
I have already fixed the problem by using the MOD and integer division to generate the four digits number that i want. Thanks for all of the help and i really appreciate it .