Results 1 to 5 of 5
-
25th Dec 2010, 12:10 AM #1OPMember
vb
i used vb and did it all !
cgworld Reviewed by cgworld on . c++ help i used vb and did it all ! Rating: 5
-
25th Dec 2010, 08:30 PM #2OPMember
the second part generated md5...
-
26th Dec 2010, 04:36 PM #3MemberWebsite's:
sborg.usWhy don't you use switch-case?
That'll be faster, easier and good looking too!
-
26th Dec 2010, 04:45 PM #4Member
Agree with V3g3t4. Switch case is preferred in these kinda cases.
A life spent making mistakes is not only more honorable, but more useful than a life spent doing nothing. ? George Bernard Shaw
?
Designer. Check my designs here.
-
26th Dec 2010, 06:34 PM #5MemberWebsite's:
ExpresShare.comwell it will be good looking,easier to understand.But when compiled it will be the same as the if else statement so it's the same thing.
Also using clases and operations will make it make the code so much cleaner and better to be understood.
well you can solve this problem i n another way.
let's divide this problem:
the main 2 operations here are:
1-choose a random number.
2-choose a random operator.
let's start with the first:
1-choose a rendom number:
We will make a function that will generate a random number for us let's call rand_number.
the random number can be:
a)between 0-9(if 10 questions)
b)between 0-19(if 20 questions)
c)between 0-29(of 30 questions)
So there is a parameter witch is the number of the question provided by the user that will be passed to this function.
2-choosing the random operator:
this one is easy you can put it as a function.let's name it rand_op().a little trick will be used here so we are going to need the generated number as a parameter for this function.to put this one up we need a table that contain the operators needed (/ - + *) and the random function will choose a number between 0 to 3 (again the rand_number function will be used).
Now the main program.
we will repeat the process(choosing a number and choosing an operator) the needed times.in it we will be printing the operation and calculating the result.
PHP Code:#the includes here
using namespace ..
int rand_nuber(int n)
{//returns a random integer between 0 and n}
void rand_op(int n,int &res)
{
/* OP is a table contains the operators needed (/ * + -)
n is the generated number by rand_number will be used in the operation.
res will store the result of the operation. */
ope=rand_number(3);
cout<< n + op[ope];
switch ope
case 0
res=res+n;
break;
case 1
res=res-n;
break;
case 2
res=res*n;
break;
case 3
res=res/n;
break;
}
void main()
{//vars here.
//get the number of questions
max= num_question % 10;
for (i=0;i<=num_question;i++)
counter=0;
do{
x=rand_number(num_question-1);
if (counter != max)
rand_op(x,&res);
}while (max!=counter)
cout<< " = ??"
//get the result from user
//compare with the var res that u have
//tell if he's wrong or not.
}
}
}
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
themaCreator - create posts from...
Version 3.45 released. Open older version (or...