1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int validb(int b);
int validN(int N);
int solveX(int a, int b);
int solveY(int a, int b, int X, int N);
int solveZ(int i, int N, int X, int Y);
void display(int X, int Y, int Z);
int main ()
{
int a,b,N,X,Y,Z,i;
char choice;
cout<<"Enter values for a, b, and N:";
cout<<"\n\na:";
cin>>a;
cout<<"\nb:";
cin>>b;
b = validb(b);
cout<<"\nN:";
cin>>N;
N = validN(N);
X = solveX(a,b);
Y = solveY(a,b,X,N);
Z = solveZ(i,N,X,Y);
display(X,Y,Z);
cout<<"\n\nWould you like to go again? Press y to continue, n to stop.";
cin>>choice;
choice = toupper(choice);
for (;cin>>choice;)
{
if (choice=='Y')
{
system ("CLS");
return main();
}
else if (choice=='N')
{
cout<<"\n\nThank you! Goodbye";
return 0;
}
}
}
int validb(int b)
{
while (b<=0)
{
cout<<"Invalid input, b must be greater than 0.\nPlease reenter values.";
cout<<"b:";
cin>>b;
}
}
int validN(int N)
{
while (N<=0)
{
cout<<"Invalid input, N must be greater than 0.\nPlease reenter values.";
cout<<"N:";
cin>>N;
}
}
int solveX(int a, int b)
{
return (a*b*b)+(a/sqrt(b));
}
int solveY(int a, int X, int N, int b)
{
return (a*X)+(a+N/b);
}
int solveZ(int i, int N, int X, int Y)
{
int f;
unsigned factorial = 1;
f = N-1;
for(int i = 1; i<=f; ++i)
{
factorial *= i;
}
return (i/(X-Y));
}
void display(int X, int Y, int Z)
{
cout<<fixed<<setprecision(3)<<endl;
cout<<"\n\nThe values for X, Y, and Z are:";
cout<<"\nX:"<<X;
cout<<"\nY:"<<Y;
cout<<"\nZ:"<<Z;
}
|