samedi 27 juin 2015

How to use randomly generated number in switch statement?

i am making a simple program that displays the behaviour of the person from the sentences that i write in switch statement cases. I want to randomly generate a number between 1 and 10 and use it in "switch(this place)". So far, i have written the following code and stuck here..

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int rand_range(int low, int high)
{
  return rand()%(high-low) + low;
}
int main()
{
    srand(time(NULL));
    cout<<"Hi!, this program tells you about your behaviour"<<endl;
    cout<<"press enter to continue";
    cin.get();

    switch(    )
    {
    case 1:
        {
            cout<<"you are rude !";
        }
    case 2:
        {
            cout<<"you are smart";
        }
    case 3:
        {
            cout<<"you try to prove yourself special all the time";
        }
    case 4:
        {
            cout<<"you are good in sarcasm";
        }
    case 5:
        {
            cout<<"you look dumb, but deep inside you are intelligent";
        }
    case 6:
        {
            cout<<"you are always ready for a debate with someone";
        }
    case 7:
        {
            cout<<"you are very lazy";
        }
    case 8:
        {
            cout<<"you are dumber than what you look";
        }
    case 9:
        {
            cout<<"you always try to help others";
        }
    case 10:
        {
            cout<<"you have good decision making capabilities";
        }
    default:
        {
            cout<<"something wrong";
        }
    }
}




Aucun commentaire:

Enregistrer un commentaire