[ create a new paste ] login | about

Link: http://codepad.org/7JoosIc4    [ raw code | output | fork ]

C++, pasted on Dec 13:
#include <iostream>
#include <fstream>

using namespace std;

void ascii (int number);
bool raffle (int number);
const int cArray=5;




int main () 
{       

    int value;

    char option = 'r';




    cout <<"Enter a positive integer number: " <<endl;
    cin >>value;
    cout <<endl;


    cout <<"A[scii]" "\t\tR[affle]" "\t\tE[xit]" <<endl;
    cout <<"Please select an option: " <<endl;
    cin >>option;
    cout<<endl;

    switch (option)
    {
        case 'a':
        case 'A':

            ascii(value);
            break;

        case 'r':
        case 'R':
            ofstream outfile("G:/File3.txt", ios::out);
            if(!outfile.is_open())
            {
                cout<<"File could not be opened"<<endl;
                exit(1);
            }
            if (raffle(value)==1)
            {
                outfile<<"The number "<<value<<"is present in the array."<<endl;
            }
            else
            {
                outfile<<"The number "<<value<<"is not present in the array."<<endl;
            }
            outfile.close();
            break;
    }
            return 0;
}


void ascii (int value)
{

    if (48 <= value && value <= 57)
    {
        cout <<"The number you have entered corresponds to a digit in the ASCII table." <<endl;
    }
    else if(65 <= value && value <= 90)
    {
        cout <<"The number you have entered corresponds to an uppercase letter in the ASCII table." <<endl;
    }
    else if (97 <= value && value <= 122)
    {
        cout <<"The number you have entered corresponds to a lowercase letter in the ASCII table." <<endl;
    }
    else  
    {
        cout <<"The number you have entered corresponds to none of the above." << endl;
    }

}

bool raffle (int value)
{   
    int random[cArray];
    srand(time(NULL));
    for (int i=0; i<5; i++)
    {
        random[i]= 0+rand()%(100+1-0);
        cout<<random[i]<<" "<<endl;
    }

    for (int j=0; j<5; j++)
    {
        if (value == random[j])
        {
            cout << "\n" <<j<<endl;

            return true;
        }
    }
            cout << "Number not present."<<endl;
            return false;



}


Output:
1
2
3
4
5
6
Enter a positive integer number: 

A[scii]		R[affle]		E[xit]
Please select an option: 

File could not be opened


Create a new paste based on this one


Comments: