Answer to Question #260519 in C++ for malika

Question #260519

Double any element's value that is less than controlValue. Ex: If controlValue = 10, then dataPoints = {2, 12, 9, 20} becomes {4, 12, 18, 20}.

#include <iostream>

using namespace std;


int main() {

  const int NUM_POINTS = 4;

  int dataPoints[NUM_POINTS];

  int controlValue;

  int i;


  cin >> controlValue;


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

   cin >> dataPoints[i];

  }


  /* Your solution goes here */


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

   cout << dataPoints[i] << " " ;

  }

  cout << endl;


  return 0;

}


1
Expert's answer
2021-11-07T15:54:54-0500
#include <iostream>


using namespace std;






int main() {


  const int NUM_POINTS = 4;


  int dataPoints[NUM_POINTS];


  int controlValue;


  int i;






  cin >> controlValue;






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


   cin >> dataPoints[i];


  }




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


   if(dataPoints[i]<controlValue){
   	dataPoints[i] = dataPoints[i] * 2;
   }
   else{
   	dataPoints[i] = dataPoints[i];
   }


  }






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


   cout << dataPoints[i] << " " ;


  }


  cout << endl;






  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