Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that initially asks the user to enter a positive integer number.

ID: 3622565 • Letter: W

Question

Write a program that initially asks the user to enter a positive integer number.
After the acquisition of the number, it displays the following:

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

Then, if the user selects:

- a (lowercase or uppercase): the program calls a user-defined function void ascii (int number) that displays whether the ASCII argument corresponds to digit, an uppercase letter, a lowercase letter or none of the above.

- r (lowercase or uppercase): the program calls a user-defined function bool raffle (int number) that takes the number input by the user as a parameter, generates an array of 5 random numbers ranging from 0-100 and displays then in a row. If the number passed as argument is present in the array, then it displays the position of the array where the number is found and the function returns true. If the number is not present, then it displays "number is not present" and the function returns false. Subsequently, the main() function saves the string "The number XX is present in the array" on the file, where 'XX' is the actual number,or saves the string "The number XX is not present in the array"

the file name is c:/FileHW7.txt

-e (lowercase or uppercase): the program exits.



 



--------------------------------------------------------------------------------------------------------------------------------

Problem: The following program successfully does all the operations correctly, except for the highlighted portion i have given

Subsequently, the main() function saves the string "The number XX is present in the array" on the file, where 'XX' is the actual number,or saves the string "The number XX is not present in the array".

Can someone please help in making my code work properly. The problem lyes in case 'r': case 'R': part. The main() function does not save the string "The number XX is not present in the array" and that is what i am having difficulty in.  I am new with C++, and dont know what to do to fix this issue.

--------------------------------------------------------------------------------------------------------------------------------

Code:

#include <iostream>
#include <iomanip>
#include <ctime>
#include <fstream>

//function prototypes
void ascii (int number);
bool raffle (int number);

using namespace std;

int main()
{

    //Variable Declaration
    int number;
    char select;
   
    //opens File
    ofstream output("c:/FileHW7.txt", ios::out);
   
    //User is asked to input positive integer
    cout<<endl;
    cout<<"Please enter a positive integer number: ";
    cin>>number;
    cout<<endl;

    //User is then given three option to choose from
    cout<<"A[scii] R[affle] E[xit]";
    cout<<endl;
    cout<<"Please select an option:";
    cin>>select;
    cout<<endl;

    switch (select)   
   
    {//start of the switch
    case 'a':
    case 'A':
            ascii(number);
            break;

    case 'r':
    case 'R':
           
            if(raffle(number)==true);//If raffle returns a true value, writes that value to FileHW7.txt
            output<<"The number "<<number<<" is present in the array";
            output.close();
            break;
           
            if(raffle(number)==false);
            output<<"The number "<<number<<" is not present in the array";
            output.close();
            break;
       
       
    case 'e':
    case 'E':       
        return 0;    //exits the program
   
    }//End of switch

}//End of main()

//if A[scii] option is chosen, this operation will determine if integer number is upper, lower, or digit
void ascii (int number)   

{
    if(number>47 && number<58)
        cout<<"The number corresponds to a digit"<<endl<<endl;
    else
    if(number>64 && number<90)
        cout<<"The number corresponds to a uppercase letter"<<endl<<endl;
    else
    if(number>96 && number<123)
        cout<<"The number corresponds to a lowercase letter"<<endl<<endl;
    else
    cout<<"The number does not correspond to uppercase letter, lowercase letter, or digit"<<endl<<endl;
   
}//End of void ascii(int number)   
   
//if R[affle] option is chosen, this operation generates an array of 5 random numbers (0-100)
   
    bool raffle(int number)
   
    {//Start of the raffle function
   
    int array[6];
    int count=0;
    srand(time(NULL));

    for(int i=0; i<5; i++)   
        {
        array[i]=rand() % 101;
        cout<<setw(8)<<array[i];
        }
   
    cout<<endl;   

//This operation scans the array given, and finds out the position of the number, resulting in given a true value
    for(int i=0; i<5; i++)
    {
        if(number==array[i])
            {
            cout<<endl;
            cout<<"The number can be found in position "<<i+1<<" of the array"<<endl<<endl;//output
            return true;
            }
    }

//If the number is not present in array, it returns false
   
        cout<<endl;
        cout<<"The number was not found in the array"<<endl<<endl;//output
        return false;
       
   
   
}//End of raffle operation
   
   
  



 



 



 



 



Explanation / Answer

#include <iostream.h>
#include <iomanip.h>
#include <time.h>
#include <fstream.h>
#include <stdlib.h>
//function prototypes
void ascii (int number);
int raffle (int number);

int main()
{

    //Variable Declaration
    int number;
    char select;

    //opens File
    ofstream output("c:/FileHW7.txt", ios::out);

    //User is asked to input positive integer
    cout<<endl;
    cout<<"Please enter a positive integer number: ";
    cin>>number;
    cout<<endl;

    //User is then given three option to choose from
    cout<<"A[scii] R[affle] E[xit]";
    cout<<endl;
    cout<<"Please select an option:";
    cin>>select;
    cout<<endl;

    switch (select)

    {//start of the switch
    case 'a':
    case 'A':
        ascii(number);
        break;

    case 'r':
    case 'R':

        if(raffle(number)==1)//If raffle returns a true value, writes that value to FileHW7.txt
           output<<"The number "<<number<<" is present in the array";
        else
           output<<"The number "<<number<<" is not present in the array";
        output.close();
       // break;
        break;


    case 'e':
    case 'E':
    return 0;    //exits the program

    }//End of switch
   return 0;
}//End of main()

//if A[scii] option is chosen, this operation will determine if integer number is upper, lower, or digit
void ascii (int number)

{
    if(number>47 && number<58)
    cout<<"The number corresponds to a digit"<<endl<<endl;
    else
    if(number>64 && number<90)
    cout<<"The number corresponds to a uppercase letter"<<endl<<endl;
    else
    if(number>96 && number<123)
    cout<<"The number corresponds to a lowercase letter"<<endl<<endl;
    else
    cout<<"The number does not correspond to uppercase letter, lowercase letter, or digit"<<endl<<endl;

}//End of void ascii(int number)

//if R[affle] option is chosen, this operation generates an array of 5 random numbers (0-100)

    int raffle(int number)

    {//Start of the raffle function

    int array[6];
    int count=0;
    srand(time(NULL));

    for(int i=0; i<5; i++)
    {
    array[i]=rand() % 101;
    cout<<setw(8)<<array[i];
    }

    cout<<endl;

//This operation scans the array given, and finds out the position of the number, resulting in given a true value
    for(i=0; i<5; i++)
    {
    if(number==array[i])
        {
        cout<<endl;
        cout<<"The number can be found in position "<<i+1<<" of the array"<<endl<<endl;//output
        return 1;
        }
    }

//If the number is not present in array, it returns false

    cout<<endl;
    cout<<"The number was not found in the array"<<endl<<endl;//output
    return 0;



}//End of raffle operation

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote