Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am writing a C++ program and I am having problems with the incrementing. I wan

ID: 3553959 • Letter: I

Question

I am writing a C++ program and I am having problems with the incrementing. I want the array x[i] to start with the inputted vaule for f, and then double each time. i.e intial f value = 100, then it goes 100, 200, 400, 800, 1600. Here is what I have so far. Any help would be greatl appreciated.

#include <cstdlib>

#include <iostream>   //pre-processor directs - iostream talks to screen

#include <iomanip> //pre-processor directs - string

#include <cmath>   //allows math functions


using namespace std; //introduces namespace


const int size=100;


int main()

{

double x[size], y[size]; //Declares arrays

double W=100,f;

  

cout<<" Enter your frequency: ";

cin>>f;

for (int i=0;i<size;i++) //initiates, defines and sets counter

x[i]=(f*(i+i)); //initiates the first value of the array

cout<<"Frequency: "<<"Result: "<<endl; //prints column headers to screen

for (int i=0;i<size;i++) //initiates, defines and sets counter

y[i]=W+x[i]; //converts values in x array to to y array

  

for (int i=0;i<size;i++) //initiates, defines and sets counter

cout<<setprecision(6)<<setw(10)<<x[i]<<setw(25)<<y[i]<<endl; //prints values in arrays to screen

cout<<endl;

  


return 0;

}

Explanation / Answer

#include <cstdlib>

#include <iostream> //pre-processor directs - iostream talks to screen

#include <iomanip> //pre-processor directs - string

#include <cmath> //allows math functions


using namespace std; //introduces namespace


const int size=100;


int main()

{

double x[size], y[size]; //Declares arrays

double W=100,f;


cout<<" Enter your frequency: ";

cin>>f;

//x[0]=f;

for (int i=0;i<size;i++) //initiates, defines and sets counter

{

x[i]=f;

f=f*2;


} //initiates the first value of the array


cout<<"Frequency: "<<"Result: "<<endl; //prints column headers to screen

for (int i=0;i<size;i++) //initiates, defines and sets counter

y[i]=W+x[i]; //converts values in x array to to y array


for (int i=0;i<size;i++) //initiates, defines and sets counter

cout<<setprecision(6)<<setw(10)<<x[i]<<setw(25)<<y[i]<<endl; //prints values in arrays to screen

cout<<endl;



return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote