The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 2 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Please help me with my code. C++
Â
Question:
Â
Load 10 integers into an array, then prompt the user for a number from 0 to 9. Display the element at the array position the user selects. For example:
Reading in: 77, 33, 88, 99, 22, 55, 11, 44, 66, 0
Enter a number from 0 to 9: 3
Element number 3 is 99
Â
Current code:
#include <iostream>
Â
using namespace std;
Â
int main()
Â
{
Â
int arr[10];
Â
for(int i=0;i<10;i++)
Â
{
Â
cin>>arr[i];
Â
}
Â
cout<<"Reading in: ";
Â
for(int i=0;i<10;i++)
Â
{
Â
cout<<arr[i]<<", ";
Â
}
Â
cout<<"nEnter a number from 0 to 9: ";
Â
int n;
Â
cin>>n;
cout << n << endl;
Â
if(n<0 || n>9)
Â
{
Â
cout<<"Number is out of range.n";
Â
}
Â
else
Â
cout<<"Element number "<<n<<" is "<<arr[n]<<endl;
Â
return 0;
Â
}
Â
Output vs Expected output. How do I remove the comma at the end?
Â
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly