help!!!!!!Metal Cutting Paramter Optimization Program

#include <iostream>
#include <cmath>
#include <string>
using namespace std;

int main()
{
int program = 0;
while (program == 0){

//Program Welcome and Program Definition
cout << "Hello EN 441! Welcome to Metal Cutting Parameter Optimization Program (2013) \n By Carina Estrada\n\nThis program will be used to minimize the production cost per part subjected to all applicable constraints."<<endl;

int run = 0;
while (run == 0){
//User Input: Parameter

cout << "\nWe Will Start By Entering Parameters \n" << endl;
cout << "\n--------First We Will Enter Physical Parameters--------" << endl;
//Maximum Speed
int maximumSpeed = 0;
double vmax;
while (maximumSpeed == 0){
cout << "Please Enter Maximum Speed:" << endl;
cin >> vmax;
if (vmax > 0){
maximumSpeed++;}
else{
cout << "Entry Is Invalid" <<endl;}
}

//Minimum Speed
int minimumSpeed = 0;
double vmin;
while (minimumSpeed == 0){
cout << "\nPlease Enter Minimum Speed: \n(Minimum Speed Must Be Less Than Maximum Speed)" << endl;
cin >> vmin;
if (vmin > 0 && vmin < vmax){
minimumSpeed++;}
else{
cout << "Entry Is Invalid" <<endl;}
}

//Maximum Feed Rate
int maximumFeed = 0;
double fmax;
while (maximumFeed == 0){
cout << "\nPlease Enter Maximum Feed Rate:" << endl;
cin >> fmax;
if (fmax > 0){
maximumFeed++;}
else{
cout << "Entry Is Invalid" << endl;}
}

//Minimum Feed Rate
int minimumFeed = 0;
double fmin;
while (minimumFeed == 0){
cout << "\nPlease Enter Minimum Feed Rate:\n(Minimum Feed Rate Must Be Less Than Maximum Feed Rate)" << endl;
cin >> fmin;
if (fmin > 0 && fmin < fmax){
minimumFeed++;}
else{
cout << "Entry Is Invalid" << endl;}
}

//Maximum Cutting Force
int maximumForce = 0;
double cfmax;
while (maximumForce == 0){
cout << "\nPlease Enter Maximum Cutting Force:" << endl;
cin >> cfmax;
if (cfmax > 0){
maximumForce++;}
else{
cout << "Entry Is Invalid" << endl;}
}

//Maximum Power Available
int maximumPower = 0;
double pmax;
while (maximumPower == 0){
cout << "\nPlease Enter Maximum Power Available:" << endl;
cin >> pmax;
if (pmax > 0){
maximumPower++;}
else{
cout << "Entry Is Invalid" << endl;}
}

//Efficiency of Machine
int efficiency = 0;
double n;
while (efficiency == 0){
cout << "\nPlease Enter Efficiency Of Machine:\n(Must Be Less Than Or Equal To 1)" << endl;
cin >> n;
if (n > 0 && n <=1){
efficiency++;}
else{
cout << "Entry Is Invalid" << endl;}
}

cout <<"\n\n\n--------Now We Will Enter Cut Parameters--------" << endl;

//Length of Cut
int lengthofCut = 0;
double l;
while (lengthofCut == 0){
cout << "\n\nPlease Enter Length Of Cut:" << endl;
cin >> l;
if (l > 0){
lengthofCut++;}
else{
cout << "Entry Is Invalid" << endl;}
}

//Diameter of Piece
int diameter = 0;
double di;
while (diameter == 0){
cout << "\n\nPlease Enter Diameter:" << endl;
cin >> di;
if (di > 0){
diameter++;}
else{
cout << "Entry Is Invalid" << endl;}
}

//Beta
int beta = 0;
double b;
while (beta == 0){
cout << "\n\nPlease Enter Beta:" << endl;
cin >> b;
if (b > 0){
beta++;}
else{
cout << "Entry Is Invalid" << endl;}
}

//Delta
int delta = 0;
double d;
while (delta == 0){
cout << "\n\nPlease Enter Delta:" << endl;
cin >> d;
if (d > 0){
delta++;}
else{
cout << "Entry Is Invalid" << endl;}
}

//Alpha(8)
int alphaeight = 0;
double ae;
while (alphaeight == 0){
cout << "\n\nPlease Enter Alpha(8):\n(Input Must Be Between 0.9 And 1.4)" << endl;
cin >> ae;
if (ae >= 0.9 && ae <= 1.4){
alphaeight++;}
else{
cout << "Entry Is Invalid" << endl;}
}

//Alpha(9)
int alphanine = 0;
double an;
while (alphanine == 0){
cout << "\n\nPlease Enter Alpha(9):\n(Input Must Be Between -0.2 And 0.05)" << endl;
cin >> an;
if (an >= -0.2 && an <= 0.05){
alphanine++;}
else{
cout << "Entry Is Invalid" << endl;}
}

//Alpha(10)
int alphaten = 0;
double at;
while (alphaten == 0){
cout << "\n\nPlease Enter Alpha(10):\n(Input Must Be Between 0.55 And 0.95)" << endl;
cin >> at;
if (at >= 0.55 && at <= 0.95){
alphaten++;}
else{
cout << "Entry Is Invalid" << endl;}
}

cout <<"\n\n\n--------Now We Will Enter Time Parameters--------" << endl;

//Tool Changing Time
int toolchangingTime = 0;
double tc;
while (toolchangingTime == 0){
cout << "\n\nPlease Enter Tool Changing Time:" << endl;
cin >> tc;
if (tc > 0){
toolchangingTime++;}
else{
cout << "Entry Is Invalid" << endl;}
}

cout <<"\n\n\n--------Now We Will Enter Cost Parameters--------" << endl;

//Labor Cost
int laborCost = 0;
double co;
while (laborCost == 0){
cout << "\n\nPlease Enter Labor Cost:" << endl;
cin >> co;
if (co > 0){
laborCost++;}
else{
cout << "Entry Is Invalid" << endl;}
}

//To0l Cost
int toolCost = 0;
double ct;
while (toolCost == 0){
cout << "\n\nPlease Enter Tool Cost:" << endl;
cin >> ct;
if (ct > 0){
toolCost++;}
else{
cout << "Entry Is Invalid" << endl;}
}

//Review Your Inputs
cout <<"\n\n--------Let's Review Your Inputs--------" <<endl;
cout <<"\n\nPHYSICAL PARAMETERS\n\nMaximum Speed:" << vmax <<" Minimum Speed:" << vmin << endl;
cout <<"Maximum Feed Rate:" << fmax <<" Minimum Feed Rate:" << fmin << endl;
cout <<"Maximum Cutting Force:" << cfmax <<" Maximum Power Available:" << pmax << endl;
cout <<"Efficiency Of Machine:" << n << endl;

cout <<"\n\nCUT PARAMETERS\n\nLength Of Cut:" << l <<" Diameter: " << di << endl;
cout <<"Beta:" << b << " Delta:" << d << endl;
cout <<"Alpha(8):" << ae << " Alpha(9):" << endl;
cout <<"Alpha(10):" << at << endl;

cout <<"\n\nTIME PARAMETERS\n\nTool Change Time:" << tc << endl;

cout <<"\n\nCOST PARAMETERS\n\nLabor Cost:" << co <<" Tool Cost:" << ct << endl;

Last edited on
REST OF CODE!!!!!

//Change If Neccessary For Inputs

//If They Choose Yes
int yesno = 0;
while (yesno == 0){
cout <<"\n\nNow That You Have Seen Your Inputs, Would You Like To Change Any?" <<endl;
cout <<"If YES Enter 1\nIf NO Enter 2" << endl;
int yn;
cin >> yn;
if (yn == 2){
cout << "\n\n--------It's Finally Time To Calculate Optimal Speed And Feed!--------" << endl;


const int size=10;
short cppp[size]={0};
short vv[size];
short ff[size];

//Limits On Cutting Speed
int answer = 0;
double v;
double vopt, fopt;
for (v = vmin; v <= vmax; v++){
//Limist On Machine Feed
double f;
for (f = fmin; f <= fmax; f++){
//Tool Life Equation
double t;
t = (0.34*((pow(10,12.4))*(pow(v,-3.7))*(pow((100*f),-1.4))));
//Machining Time Equation
double tm;
tm = (3.14*di*l)/(1000*v*f);
//Cutting Force Equation
double cf;
cf = (pow(10,ae))*(pow(v,an))*(pow((100*f),at));
//Cutting Power Equation
double cp;
cp = (cf*v)/(6120*n);
//Cost Per Part Equation
double cpp;
cpp = (co*tm)+((tm)/(t))*((co*tc)+ct);

for (short i=1; i < size; i++){
if ((f*pow(v,d)) >= b && cf <= cfmax && cp <= pmax){
cppp[i] = cpp, vv[i] = v, ff[i] = f;}}
yesno++;
run++;}}

short mcpp = cppp[0];
for (short i=1; i < size; i++){
if (cppp[i]<=mcpp){
mcpp = cppp[i],vopt=vv[i],fopt=ff[i];}
}

//Optimal Results
cout << "Minimum Cost Per Part:" << mcpp << endl;
cout << "Optimal Cutting Speed:" << vopt << endl;
cout << "Optimal Feed Rate:" << fopt << endl;
}
//If They Choose No
else if (yesno == 1){
cout << "You Have Chosen To Change Your Inputs" << endl;
yesno++;}
else {
cout << "\nInvalid Command" << endl;}
}}

//Would You Like To Run Again
int end = 0;
int endnow;
while (end == 0){
cout << "Thank You For Using This Program :)" << endl;
cout << "If You Would Like To Run The Program Again Press 1\nIf You'd Like To Quit Press 2" << endl;
cin >> endnow;

//If User Presses 1
if (endnow == 1){
cout << "Let Us Have Some More Fun!" << endl;
end++;}

//If User Presses 2
else if (endnow == 2){
cout << "I DID IT!!! Good Bye" << endl;
end++;
program++;}

//Invalid Answer
else {
cout << "Invalid Command" << endl;}
}
}
}
I am working on this code. I can't get my array to work and actually choose the optimal cost per part, feed, and speed. If someone can please take a look at it and help me that would be awesome .!! I am a beginner so I know the code looks yucky.

Here are the inputs that I know should work:
Maximum Speed-1004.8
Minimum Speed-12.6
Maximum Feed-5.6
Minimum Speed-0.01
Diameter-100
Length-250
Labor Cost-50
Tool Cost-75
Tool changing time-0.5
efficiency -0.75
beta-1300
delta-2
alpha8-1.0345
alpha9- -0.0827
alpha10-0.7692
Cutting Force-170
Power-7.5

please use those inputs now here is my code!!!
When posting code, please enclose it in code tags to make it easier for everyone else to read.

What do you mean by "I can't get my array to work". What behaviour are you seeing that you think is incorrect?
Topic archived. No new replies allowed.