C++ array program -
i'm confused when comes arrays , i've got mini-project on using them i'm stuck @ part in program , don't know next, can help?
the question is:
"write c++ program reads 5 integers screen (provided user) , determines largest integer. must use array store 5 integers.
the following shows sample output of program. enter 5 integers: 15 36 -8 92 56 largest integer 92 "
what i've got far:
#include <iostream> #include <string> using namespace std; int main() { int userintegers[5]; cout<<"enter 5 integers: "; cin>>userintegers[0]; //system("pause"); return 0; }
here thing have do. need use for or while loop number of user input , store them in array.
int userintegers[5]; int largest = 0; cout<<"enter 5 integers: "; (int i=0; i<5; i++) //use loop upto how many numbers need input. { cin>>userintegers[i];//get input user , store in array @ index /*if input larger prev largest or special case handle if values entered less zero.*/ if(largest < userintegers[i] || largest == 0) { largest = userintegers[i];//assign largest number variable. } } cout<<"largest integer is: "<<largest;
Comments
Post a Comment