Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,394 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,133 people online right now. Registration is fast and FREE... Join Now!




rand () funtion

 
Reply to this topicStart new topic

rand () funtion

loulz
23 Oct, 2006 - 12:48 PM
Post #1

New D.I.C Head
*

Joined: 23 Oct, 2006
Posts: 3


My Contributions
I need to write a program that helps a student learn the multiplication table from 2 to 9 by asking him questions like "what is 3 *8" using the rand function.

can someone plz explain to me what is the rand?
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Rand () Funtion
23 Oct, 2006 - 02:51 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
The rand() function generates pseudo random numbers for use in various applications. Don't forget to see with srand() first.

http://www.cplusplus.com/ref/cstdlib/rand.html
User is offlineProfile CardPM
+Quote Post

loulz
RE: Rand () Funtion
23 Oct, 2006 - 09:23 PM
Post #3

New D.I.C Head
*

Joined: 23 Oct, 2006
Posts: 3


My Contributions
CODE
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    
    for (int i=2; i<=9; i++)
    {
        i=rand();
        int num1=rand()%10;
        int num2=rand()%10;
        int p=num1*num2;
        cout<<"How much is "<<num1<<" times "<<num2<<"?";
        cin>>p;
        int r;
        r=p;
        

            while (r=p)
            {
                cout<<"Very Good!"<<endl;
                cout<<"How much is "<<num1<<" times "<<num2<<"?";
                cin>>r;
            }
        if (r!=p)
                cout<<"No. Try Again."<<endl;
                
    }
    return 0;
}


ok i get what the rand() function is. but now i only seem to get 2 numbers repeating over and over which are 7 times 4. how can i make the next question (how much is num1 times num2) have different values for num1 and num2.. ?
also, if the person enters the wrong answer, how can i make the same question reappear?
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 02:40AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month