C++ Create an array of 1000 double datatype elements, store 7.5 times the array
ID: 3590150 • Letter: C
Question
C++
Create an array of 1000 double datatype elements, store 7.5 times the array slot number as the value in each array slot.
Ask the user to enter an integer between 0 and 999 – print the value of that element of the array (if the user entered 121 you would print the contents of array slot 121 which would be 907.5).
Input validation: Do not check out of range values! Instead inform the user that the value is out of range.
Create an array of 1000 double datatype elements, store 7.5 times the array slot number as the value in each array siot Ask the user to enter an integer between 0 and 999 -print the value of that element of the array (if the user entered 121 you would print the contents of array slot 121 which would be 907.5). Input validation: Do not check out of range values! Instead inform the user that the value is out of range. Example Output: Test Case 1: Enter an array slot number : The value in array slot 48 is 380 Test Case 2: Enter an array slot number: The value in array slot is e Test Case 3: Enter an array slot number: The value in array slot 999 is 7492.5 Test Case 4: Enter an array slot number : Value out of range. Test Case 5: Enter an array slot number: Value out of range.Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
double a[1000];
int n;
cout<<"Enter an array slot number: "<<endl;
cin >> n;
if(n < 0 || n > 999) {
cout<<"Value out of range"<<endl ;
} else {
a[n] = n * 7.5;
}
cout<<"The value is array slot "<<n<<" is "<<a[n]<<endl;
return 0;
}
Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.