Answer to Question #260510 in C++ for malika

Question #260510

Write a for loop to populate array userGuesses with NUM_GUESSES integers. Read integers using cin. Ex: If NUM_GUESSES is 3 and user enters 9 5 2, then userGuesses is {9, 5, 2}.


#include <iostream>

using namespace std;


int main() {

  const int NUM_GUESSES = 3;

  int userGuesses[NUM_GUESSES];

  int i;


  /* Your solution goes here */


  for (i = 0; i < NUM_GUESSES; ++i) {

   cout << userGuesses[i] << " ";

  }


  return 0;

}


1
Expert's answer
2021-11-04T03:49:57-0400




#include <iostream>


using namespace std;






int main() {


  const int NUM_GUESSES = 3;


  int userGuesses[NUM_GUESSES];


  int i;






  for(int j=0; j<NUM_GUESSES; j++){
  	cin>>userGuesses[j];
  }






  for (i = 0; i < NUM_GUESSES; ++i) {


   cout << userGuesses[i] << " ";


  }






  return 0;


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS