Ask Question
18 October, 05:10

Write a program that continually prompts the user for an integer input until input is entered that is less than 0. Each input that is accepted is appended to an array named inputs, until an invalid input is given. When the first invalid input is entered the program prints the array and exists.

+4
Answers (1)
  1. 18 October, 05:45
    0
    Following are the program in the C+ + Programming Language:

    #include / /header file

    using namespace std; //namespane

    //set main method

    int main () {

    int a[100]; / /set integer type array variable

    int value, i = 0; / /set integer variables

    cout<<"Enter less than 0 to exit:"<
    cout<<"Enter the integer numbers:"<
    do{ / /set do while

    cin>>value; / /get input from the user

    a[i++] = value; / /append elements in array

    }while (value>=0);

    i--;

    cout<<"/nArray are:"<
    for (int k = 0; k
    cout<
    }

    return 0;

    }

    Output:

    Enter less than 0 to exit:

    Enter the integer numbers:

    1

    2

    3

    4

    5

    -1

    Array are:

    1 2 3 4 5

    Explanation:

    Here, we set the integer data type main method "main () " and inside it:

    we set integer type array variable with index value 100. we set two integer type variable "value" and "i" initialize value 0. we set the do-while loop in which we get the input from the user and and append in the array and pass condition if the value is greater then equal to 0. Finally, set for loop and print the elements of an array.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program that continually prompts the user for an integer input until input is entered that is less than 0. Each input that is ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers