Attached ImageSomeone Please help me fix the this problem.I was using the if statement to determine the material is copper, and then I would like to use arrays to print out different type of length and material. Thank You.このchar配列が
enter code here
#include <stdlib.h>
#include <iostream>
using namespace std;
float steelbar();
float steelrod();
char printMenu();
void testing(float length, float area, float stress, float price);
int main()
{
char Choice;
float result;
cout<<"\t\tWelcome to Smart Calculating System\n";
cout<<"\t\t_______________________________________\n";
Choice = printMenu();
if (Choice == 'A' || Choice == 'a')
{
result = steelbar();
}
else if (Choice == 'B' || Choice == 'b')
{
result = steelrod();
}
else
{
printf("Invalid input!\n");
fflush(stdin);
getchar();
}
}
char printMenu()
{
char choice;
cout<<" Please choose a type:\n";
cout<<" A/a = Steel bar B/b = Steel rod\n";
cout<<"Answer = "<<endl;
cin>>choice;
cout<<"\n";
return choice;
}
/////////////////////////////////////////////////////////////////
float steelbar()
{
float length, width, height, pressure, area, stress, price;
int program=1;
while(program == 1)
{
cout<<"Please enter length: "<<endl;
cin>>length;
cout<<"Please enter width: "<<endl;
cin>>width;
cout<<"Please enter height: "<<endl;
cin>>height;
cout<<"Please enter pressure: "<<endl;
cin>>pressure;
area = height * width;
stress = pressure/area;
cout<<"\nThe stress is : "<<stress<<endl;
if (stress <= 690)
{
testing(length, area, stress, price);
fflush(stdin);
getchar();
cout<<"\n";
cout<<" Do you wish to continue? (Yes=1 /No=0)\n";
cout<<"Answer = ";
cin>>program;
if (program == 1)
{
printMenu();
}
else (program == 0);
{
return 0;
}
}
else if (stress > 690)
{
cout<<"\n";
cout<<" Please enter stress less than 690 MPA\n";
cout<<" Do you wish to continue? (Yes=1 /No=0)\n";
cout<<"Answer = "<<endl;
system("cls");
}}
return price;
}
/////////////////////////////////////////////////////////////////
float steelrod ()
{
float length, diameter, pressure, area, stress, price ,density, rate ;
int program;
while(program == 1)
{ cout<<"Please enter length: "<<endl;
cin>>length;
cout<<"Please enter diameter: "<<endl;
cin>>diameter;
cout<<"Please enter pressure: "<<endl;
cin>>pressure;
area = (3.14159 * diameter * diameter)/4;
stress = pressure/area;
cout<<" The stress is : "<<stress;if (stress <= 690)
{
testing(length, area, stress,price);
fflush(stdin);
getchar();
system("cls");
cout<<"\n";
cout<<" Do you wish to continue? (Yes=1 /No=0)\n";
cout<<"Answer = ";
cin>>program;
if (program == 1)
{ system("cls");
main();
}
else (program == 0);
{return 0;
}
}
else if (stress > 690)
{
cout<<"\n";
cout<<" Please enter stress less than 690 MPA\n";
cout<<" Do you wish to continue? (Yes=1 /No=0)\n";
cout<<"Answer = "<<endl;
cin>>program;
system("cls");
}
return price;
}
}
/////////////////////////////////////////////////////////////////
void testing(float length, float area, float stress, float price)
{
const char *material[30];
int i, j;
if(stress <= 70)
{
material[i] = "Copper";
price = length * area * 10 * 1.5;
}
else if(stress >70 && stress <= 130)
{
material[i] = "Cast iron";
price = length * area * 15 * 1.8;
}
else if(stress >130 && stress <= 200)
{
material[i] = "Brass";
price = length * area * 17 * 2.0;
}
else if(stress >200 && stress <= 690)
{
material[i] = "ASTM A51";
price = length * area * 22.5 * 2.20;
}
for(i=0;i<3;i++)
{
cout<<"Material : "<<material[i];
cout<<"\nThe total price is : RM"<<price<<endl;
}
}
でreleavantコード、予想される出力と観測出力、(デバッグから)suspectionを投稿してください詳細 – Smeeheey
を投稿してください**テキスト**形式。 –