In: Computer Science
can someone change this code so that timestandard can be calculated at the end of the code using the inputs n,RF,PFD, and the measured cycles, instead of being called from the beginning of the code
using namespace std;
float timestandard(float time, float rf, float pfd)
{
return((time / 100) * rf * (1 + pfd)); /* calculating the time standard using the given formula*/
}
int main()
{
int n, rf, pfd, x;
/* inputs are taken*/
cout << "**** Welcome to the Time Study Program ****";
cout << "\nEnter the number of operations for the given operation being performed";
cout << "\nNumber of elements:";
cin >> n; // Input for # elements
cout << "\n\nEnter the Performance Rating<PR> factor as a percentage";
cout << "\nRF:";
cin >> rf; // Input for PR
cout << "\n\nEnter the Personal Fatigue Delay<PFD> value as a percentage";
cout << "\nPFD:";
cin >> pfd; // Input for PFD
cout << "\n\nNow enter the measured cycle times in hundreths of a minute for each element";
for (int i = 0;i < n;i++) // Input for each measured cycle
{
cout << "\nElement " << i + 1 << ": ";
cin >> x;
}
/*rest of the calculation and function calling is done here*/
float r = (float)rf / 100;
float p = (float)pfd / 100;
cout << "\n\n**** Time Study Results ****";
cout << "\nThe Time Standard is: Ts = " << timestandard(x, r, p) << " minutes";
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int n, i = 0;
float RF, PFD, Tn = 0, Ts;
cout << "**** Welcome to the Time Study Program ****"
<< endl;
cout << "\nEnter the number of elements for the given
operation being performed" << endl;
cout << "Number of Elements: ";
cin >> n;
if (n < 0)
{
cout << "\nNumber of elements cannot be negative! Try
again.";
return 0;
}
cout << "\nEnter the Performance Rating (PR) factor as a
percentage" << endl;
cout << "RF: ";
cin >> RF;
if (RF < 0)
{
cout << "\nPercentage cannot be negative! Try again.";
return 0;
}
RF = RF / 100.0;
cout << "\nEnter the Personal Fatigue Delay (PFD) value as
a percentage" << endl;
cout << "PFD: ";
cin >> PFD;
if (PFD < 0)
{
cout << "\nPercentage cannot be negative! Try again.";
return 0;
}
PFD = PFD / 100.0;
cout << "\nNow enter the measured cycle times in
hundredths of a minute for each element" << endl;
cout << "(Note: Time entered should be relative not
absolute)\n";
float ET[n], temp[n];
while (i < n)
{
cout << "\n Element " << i + 1 << ": ";
cin >> ET[i];
if (ET[i] < 0)
{
cout << "\nTime cannot be negative! Try Again.";
return 0;
}
i++;
}
/*
temp[] array stores the one hundredths of minutes of corresponding
elements
*/
i = 0;
while (i < n)
{
if (i == 0)
temp[i] = ET[i] / 100;
else
temp[i] = (ET[i] - ET[i - 1]) / 100;
i++;
}
i = 0;
while (i < n)
{
Tn = Tn + temp[i];
i++;
}
Tn = Tn * RF;
Ts = Tn * (1 + PFD);
cout << "\n**** Time Study Results ****";
cout << "\nThe Time Standard is: Ts = " << Ts <<
" minutes";
return 0;
}