Update iteration result - c++

EDIT: Global variables are restricted as part of the assignment (Forgot to mention this).
The program is meant to calculate a projected population every year for a specified number of years. Here is the equation:
N = P(1 + B)(1 - D)
Where N is the new population size, P is the previous population size, B is the birth rate, and D is the death rate. B and D are decimals.
So my problem is that I can only get the first iteration's result, and I don't know how to update the result so that it is multiplied by the (1 + B) and (1 - D). My guess is that it has to do with one of the combined assignment operators, but I haven't had success.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int get_pop();
int get_numYears();
double get_annBirthRate();
double get_annDeathRate();
double pop_new(int& A, double& B, double& C, double& D);
int main()
{
int P,
num,
Y;
double B,
D,
N;
P = get_pop();
B = get_annBirthRate();
D = get_annDeathRate();
Y = get_numYears();
for (num = 1; num != Y; num++)
{
N = pop_new(P, B, D, N);
cout << "\n\nThe projected population for the end of year " << num << " is " << N << endl;
cin.ignore();
}
return 0;
}
int get_pop()
{
int pop;
cout << "Enter the starting population:" << endl;
cin >> pop;
while (pop < 2)
{
cout << "\n\nError - starting population cannot be less than 2:" << endl;
cin >> pop;
}
return pop;
}
double get_annBirthRate()
{
double annBirthRate;
cout << "\n\nEnter the annual birth rate \n(a positive percentage in decimal form):" << endl;
cin >> annBirthRate;
while (annBirthRate < 0)
{
cout << "\n\nError - annual birth rate cannot be negative:" << endl;
cin >> annBirthRate;
}
return annBirthRate;
}
double get_annDeathRate()
{
double annDeathRate;
cout << "\n\nEnter the annual death rate \n(a positive percentage in decimal form):" << endl;
cin >> annDeathRate;
while (annDeathRate < 0)
{
cout << "\n\nError - death rate cannot be negative:" << endl;
cin >> annDeathRate;
}
return annDeathRate;
}
int get_numYears()
{
int numYears;
cout << "\n\nEnter the number of years to display:" << endl;
cin >> numYears;
while (numYears < 0)
{
cout << "\n\nError - number of years cannot be less than 1:" << endl;
cin >> numYears;
}
return numYears;
}
double pop_new(int& P, double& B, double& D, double& N)
{
N = P * (1 + B) * (1 - D);
return N;
}

The values P, B, and D do not change.
Make it:
double pop_new(int P, double B, double D)
{
double N = P * (1 + B) * (1 - D);
return N;
}
and:
P = pop_new(P, B, D);
cout << "\n\nThe projected population for the end of year "
<< num << " is " << P << endl;
Note: You do not need to pass references (and if, you should have passed const double&)

Related

Unable to get decimal output in c++ code.

#include <iostream>
#include <math.h>
using namespace std;
int sum (int x);
int factorial (int y);
int greatest (int p, int q, int r);
int percentage (int m1, int m2, int m3, int m4, int m5);
int formula (int r, int h);
int voter_age (int x);
int interest (int p, int r, int t);
void swap (int x, int y);
int tables (int i, int j, int k);
int distance (double x, double y, double z);
int speed (double x, double y, double z);
int power (double x, double y, double z);
int sqroot (double x, double y, double z);
int converter (double x, double y, double z);
int inr (double x, double y, double z);
int usd (double x, double y, double z);
int mtrs(double x, double y, double z);
int main () {
int a, b;
double x, y, p, q, m1, m2, m3, m4, m5, r, h, t, i, j, k, z, ans;
cout << "MAIN MENU";
cout << "\n 1. Sum of Natural nos.";
cout << "\n 2. Factorial";
cout << "\n 3. Greatest number among 3";
cout << "\n 4. Percentage(5 subjects)";
cout << "\n 5. Volume of cylinder";
cout << "\n 6. Vote age checker";
cout << "\n 7. interest_calculator";
cout << "\n 8. Swapping nos.";
cout << "\n 9. Table of a number.";
cout << "\n 10. Distance calculator";
cout << "\n 11. Speed calculator";
cout << "\n 12. Calculate the power of a number";
cout << "\n 13. Square root calculator";
cout << "\n 14. Converter";
cout <<
"\n \n Select one of the above option typing the serial number of the
same";
cin >> a;
switch (a) {
case 1:
cout << "Enter any number";
cin >> x;
ans = sum(x);
cout << ans;
break;
case 2:
cout << "Enter any number";
cin >> y;
ans = factorial(y);
cout << ans;
break;
case 3:
cout << "Enter 3 numbers";
cin >> p >> q >> r;
ans = greatest(p, q, r);
cout << ans << " is the biggest number";
break;
case 4:
cout << "Enter marks of 5 subjects ";
cin >> m1 >> m2 >> m3 >> m4 >> m5;
ans = percentage(m1, m2, m3, m4, m5);
cout << ans << "%";
break;
case 5:
cout << "enter value of radius" << "\n";
cin >> r;
cout << "Enter value of height" << "\n";
cin >> h;
ans = formula(r, h);
cout << ans;
break;
case 6:
cout << "Enter your age" << "\n";
cin >> x;
ans = voter_age(x);
break;
case 7:
cout << "Enter principle amount " << "\n";
cin >> p;
cout << "Enter rate " << "\n";
cin >> r;
cout << "Enter time " << "\n";
cin >> t;
ans = interest(p, r, t);
cout << ans;
break;
case 8:
cout << "Enter 1st number.";
cin >> x;
cout << "Enter 2nd number";
cin >> y;
break;
case 9:
cout << "Enter a number to display its table";
cin >> i;
ans = tables(i, j, k);
cout << ans;
break;
case 10:
cout << "Enter speed in km/hr" << endl;
cin >> x;
cout << "Enter time in hours" << endl;
cin >> y;
ans = distance(x, y, z);
cout << ans << "km";
break;
case 11:
cout << "Enter distance in km" << endl;
cin >> x;
cout << "Enter time in hours" << endl;
cin >> y;
ans = speed(x, y, z);
cout << ans << "km/hr.";
break;
case 12:
cout << "Enter a number" << endl;
cin >> x;
cout << "Enter the power" << endl;
cin >> y;
ans = power(x, y, z);
cout << ans;
break;
case 13:
cout << "Enter a number" << endl;
cin >> x;
ans = sqroot(x, y, z);
cout << ans;
break;
case 14:
cout << "Select one of the following" << endl;
cout << "\n a. Currency";
cout << "\n b. Distance";
cout << "\n c. mass";
cout << "\n d. temperature" << endl;
cin >> b;
switch (b) {
case 1:
cout << "Select one of the following:" << endl;
cout << "\t 1. For INR to USD type " << endl;
cout << "\t 2. For USD to INR type " << endl;
cin >> b;
switch (b) {
case 1:
cout << "Enter amount in INR" << endl;
cin >> y;
ans = inr(x, y, z);
cout << ans << "$";
break;
case 2:
cout << "Enter amount in USD" << endl;
cin >> y;
ans = usd(x, y, z);
cout << ans << "Rs.";
break;
}
break;
case 2:
cout << "Slect one of the following" << endl;
cout << "\t Mtrs to kms and cms" << endl;
cout << "\t Kms to Mtrs and cms" << endl;
cout << "\t Cms to Mtrs and Kms" << endl;
break;
case 3:
cout << "Select one of the following" << endl;
cout << "\t Kgs to grams and pounds" << endl;
cout << "\t Grams to Kgs and Pounds" << endl;
cout << "\t Pounds to kgs and grams" << endl;
break;
case 4:
cout << "Select one of the following" << endl;
cout << "\t Celcius to Farenhite and Kelvin" << endl;
cout << "\t Farenhite to Celcius and Kelvin" << endl;
cout << "\t Kelvin to Celcius and Farenhite" << endl;
break;
}
break;
default:
cout << "please enter correct option";
}
}
int sum (int x)
{
int i, sum = 0;
for (i = 1; i <= x; i++)
sum = sum + i;
return (sum);
}
int factorial (int y)
{
int i, fact = 1;
for (i = 1; i <= y; i++)
fact = fact * i;
return (fact);
}
int greatest (int p, int q, int r)
{
int s;
if ((p > q) && (p > r))
s = p;
else if ((q > p) && (q > r))
s = q;
else if ((r > p) && (r > q))
s = r;
return (s);
}
int percentage (int m1, int m2, int m3, int m4, int m5)
{
int s, q;
s = m1 + m2 + m3 + m4 + m5;
q = s / 5;
return (q);
}
int formula (int r, int h)
{
return (r * r * h * 3.14);
}
int voter_age (int x)
{
if (x >= 18)
cout << "eligible to vote";
else if (x < 18)
cout << "Not eligible to vote, wait for " << 18 - x << " years";
return (x);
}
int interest (int p, int r, int t)
{
return (p * r * t) / 100;
}
void swap (int x, int y)
{
x = x + y;
y = x - y;
x = x - y;
cout << "Value of x is " << x << "Value of y is " << y;
}
int tables (int i, int j, int k)
{
for (j = 1; j <= 10; j++)
{
k = i * j;
cout << i << "*" << j << "=" << k << "\n";
}
return (k);
}
int distance (double x, double y, double z)
{
z = x * y;
return (z);
}
int speed (double x, double y, double z)
{
z = x / y;
return (z);
}
int power (double x, double y, double z)
{
z = pow (x, y);
return (z);
}
int sqroot (double x, double y, double z)
{
z = sqrt (x);
return (z);
}
int inr (double x, double y, double z)
{
z = y * 69.70;
return (z);
}
int usd (double x, double y, double z)
{
z = (1 / 69.70) * y;
return (z);
}
int mtrs(double x, double y, double z)
{
z = (1/1000)*y;
return(z);
}
This code is my school project in which we were asked to create functions using switch. Everything is working fine except the outputs from converter(in the 1st switch case) or any other program which has to give decimal outputs.
On selecting converter from the menu, all the operations are programmed to get output in decimals but it is rounding off the numbers.
Be aware that integral types (char, unsigned int, (u)int<n>_t, size_t) all can only hold integral values. So if you assign them the value of some floating point type, you always lose the decimals.
Let's take distance as example:
int distance (double x, double y, double z)
{
z = x * y; // distance calculated as double!
return (z); // double is cast to int -> you lose the decimals
}
If you want to keep the decimals, return a floating point type:
double distance (double x, double y, double z);
// ^^
There are some other issues, though:
At first, don't use parentheses on return values!!! They have special meaning (creating a reference) and might give you unexpected results:
decltype auto distance (double x, double y, double z)
// ^ (!)
{
return (z);
}
Here, return type is deduced, and it will get a reference to the local variable z, so you end up in undefined behaviour!
Then why do you pass z as parameter at all? You don't ever use it, so make it a local variable instead:
double distance (double x, double y)
{
double z = x * y;
return z;
}
or even shorter, don't use an intermediate variable at all and return directly (prefer this style on short calculations):
return x * y;
Sometimes, you want to have additional output parameters, then you can pass these as parameters – but to be able to receive any value outside the function, you need to pass them as either reference or pointer. Prefer references if values always have to be provided, pointers only if nullptr is considered valid input as well.
int distance (double x, double y, double& z)
// ^ (!)
{
z = x * y;
return z;
}
// use:
double distance;
int rounded = distance(10.12, 12.10, distance);
In this example, you have two result values, the distance calculated (with decimals) in the double variable and the one with decimals cut away in the int variable. Be aware that there might be overflow when the double is converted to int!
Above is a rather bad example, as output is redundant, you'd do things like these if one of the outputs has different/independent meaning:
int distance (double x, double y, double& z)
{
// check input variables x and y
if(...)
{
return INVALID_PARAMETERS; // assuming you have an enum or a #define for
}
// calculations and other checks, different return values for different errors
z = x * y;
return SUCCESS;
}
This has a bit of C programming style, in C++, think of if throwing some exception possibly is more appropriate. An alternative approach to having output parameters is returning a struct or class – think of returning 2D or 3D coordinates in a struct 'Point' or complex results with real and imaginary part in a struct – well, guess – 'Complex' (be aware that there already is std::complex, though).
In addition to change return type from int to double...
Try to run with fixed and setprecision:
fixed to not remove extra 0 and setprecision to cut after some amount of decimal digits after decimal point.
for example:
#include <iomanip> //add this include
int main()
{
cout<< fixed;
double x = sum(3);
cout<<setprecision(5)<<x;
return 0;
}
/unspecified/ setprecision (int n);
Set decimal precision
Sets the decimal precision to be used to format floating-point values on output
operations.
Behaves as if member precision were called with n as argument on the
stream on which it is inserted/extracted as a manipulator (it can be
inserted/extracted on input streams or output streams).
This manipulator is declared in header <iomanip>.

maximum power a number can be raised to with out exceeding y recursion

i have this program assignment and one part of it is trying to find the max power a number will go to(x) without exceeding a number the user inputs it not to exceed(y). we are using it in a function. this is the whole program and what i have for max power it just keeps returning 0. it is the int maxpower(int x, int y) function i am trying to figure out
#include <iostream>
#include <cmath>
using namespace std;
// meunue where you can get your options from
void menue() {
cout << "choose the following options:" << endl;
cout << "1) Power of x raised by y." << endl;
cout << "2) Find the max power a number can be raised to." << endl;
cout << "3) Print out a number with its digits in reversed order." << endl;
cout << "4) Sum of integers from 1 to n." << endl;
cout << "5) Product of integers from 1 to n." << endl;
cout << "6) Quit" << endl;
}
//functions for finding the power usign recursion
int Power(int a, int b) {
int x = 1, i;
for (i = 1; i <= b; i++) {
if (b == 0) {
return Power(a, b--);
}
else {
x = x * a;
}
}
return x;
}
int maxpower(int n, int max_value) {
int temp = temp * n;
if (temp > max_value)
return 0;
else return maxpower(n, max_value + 1);
}
int reverse(int number) {
int lastDigit, numberOfDigits, sign = 1;//sets the sign equal to one
// if number is less than 0 returns 0
if (number < 0) {
return 0;
}
else
//if a number is under 10 than it can not be switched so you times the number by 10 and switch it.
if (number < 10)
return number * sign;
lastDigit = number % 10;
number = number / 10;
numberOfDigits = log10(number) + 1;
//recursive statement that calls the function
return (lastDigit * pow(10, numberOfDigits) + reverse(number)) * sign;
}
//finding the sum
int sum(int n) {
if (n != 0) {
return n + sum(n - 1);//recursive statement
}
else {
return n;
}
}
//finding the product
int product(int n) {
int temp;
if (n <= 1) {
return 1;
}
else {
temp = n * product(n - 1);
// recursive statement setting temp == to recursive statement
return temp;//returning temp
}
}
int main() {
int a;
int x;
int y;
int length = 0;
int temp;
int results;
// calls menue and get prints all the options
do {
menue();
//inserts the choice
cin >> a;
cout << "you choose:" << a << endl;//prints the choice out.
//switch statement that will take account for the number you choose and prints the results
switch (a) {
case 1:
cout << "enter the number to raise" << endl;
cin >> x;
cout << " enter the power to raise to: " << endl;
cin >> y;
Power(x, y);
cout << "the result is:" << Power(x, y) << endl;
break;
case 2:
cout << "Enter the number to raise:" << endl;
cin >> x;
cout << "Enter the number not to exceed:" << endl;
cin >> y;
maxpower(x, y);
cout << "the result is:" << maxpower(x, y) << endl;
break;
case 3:
cout << " enter numbers to be reversed by: " << endl;
cin >> x;
temp = x;
while (temp != 0) {
length++;
temp = temp / 10;
}
reverse(x);
cout << "the result is:" << reverse(x) << endl;
break;
case 4:
cout << "enter the number to sum to: " << endl;
cin >> x;
sum(x);
cout << "the result is:" << sum(x) << endl;
break;
case 5:
cout << "enter the number to multiply to:" << endl;
cin >> y;
product(y);
cout << "the result is:" << product(y) << endl;
break;
case 6:
cout << "good bye!!" << endl;
break;
}
} while (a != 6);
return 0;
}
I don't think it's necessary to use recursion for this problem. Moreover, recursion is creating a lot of overhead while solving it with a loop works just fine. Do you have to use recursion? If so, then disregard this answer :p. But you'll find below a solution that will work.
Note the #include <math.h> bit - you need that to use pow(base, exponent).
Also, while(true) is definitely not the best practice, but as long as you have sufficient checks to get out of the loop properly then you're ok. Hence the max_iteration and the actual return statement that you're looking for.
Best of luck!
#include <iostream>
#include <math.h>
int maxpower(int n, int max_value) {
if ( n > max_value ) return 0;
int previous, current = 1;
int max_iteration = 0;
while (true) {
if (max_iteration >= 1000) return -1;
if (pow(n, current) > max_value) {
return previous;
}
previous = current;
current++;
max_iteration++;
}
}
int main() {
int x;
int y;
int result;
std::cout << "Enter the base: ";
std::cin >> x;
std::cout << "Enter the max number x^pow should not exceed: ";
std::cin >> y;
result = maxpower(x, y);
if (result == -1) {
std::cout << "Max iteration reached." << std::endl;
}
else {
std::cout << result << " is the maximum power such that " << x << "^" << result << " does not exceed " << y << std::endl;
}
return 0;
}
As an example of output:
If x = 2 and y = 32, the program will return 5 as the max power (i.e. 2^5 = 32 and is not greater than, but 2^6 > 32).
EDIT:
I realized after I posted that all of your functions are recursive, so perhaps that's a requirement for your assignment. Anyway, below is a recursive solution:
int maxpower_rec_helper(int n, int power, int max_value) {
if (pow(n, power) > max_value) return power - 1;
return maxpower_rec_helper(n, power + 1, max_value);
}
int maxpower_rec(int n, int max_value) {
if ( n > max_value ) return 0;
return maxpower_rec_helper(n, 1, max_value);
}
You'll need a helper function to give the initial power 1, and so as not to disturb your max_value.
return power - 1; is essentially the same thing as return previous; in the iterative example above.

I want the average of the two biggest variables among the three variables n1, n2, n3. Can someone help me.

I want the average of the two biggest variables among the three variables n1, n2, n3. Can someone help me. I ask the user to enter three notes will be stored in variables n1, n2, n3. then I want the program to return the average of the two biggest variables.
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
float ra[23], qte_alunos=0;
float n1[29],n2[33],n3[33],op1[22],op2[22], fina[22];
string nome[23], curso[23];
for (int i=0; i<3; i++){
cout << "digite RA: ";
cin >> ra[i];
cout << "digte nome: ";
cin >> nome[i];
cout << "digite curso: ";
cin >> curso[i];
cout << "digite N1: ";
cin >> n1[i];
cout << "digite N2: ";
cin >> n2[i];
cout << "digite N3: ";
cin >> n3[i];
if (n1[i] > n2[i] && n2[i] > n3[i]){
n1[i] = op1[i];
n2[i] = op2[i];
}
if (n2[i] > n3[i] && n3[i] > n1[i]){
n2[i] = op1[i];
n3[i] = op2[i];
}
if (n3[i] > n1[i] && n1[i] > n2[i]){
n3[i] = op1[i];
n1[i] = op2[i];
}
fina[i] = (op1[i]+op2[i])/2;
if (fina[i] > 6 ){
cout << "aprovado " << fina[i];
}
if (fina[i] > 4 && fina[i] < 5.9){
cout << "exame " << fina[i];
}
if (fina[i] < 4){
cout << "reprovado " << fina[i];
}
cout << "\n" << endl;
}
return 0;
}
If I get you right you want (sum(a, b, c) - min(a, b, c)) / 2:
#include <algorithm>
#include <iostream>
int main (int argc, const char **argv) {
double a = 1;
double b = 2;
double c = 3;
double min = std::min({a, b, c});
// double max = std::max({a, b, c});
double sum = a + b + c;
// double result = ((sum - min - max) + max) / 2;
// which is:
double result = (sum - min) / 2;
std::cout << result << '\n';
}

Disruption in the count for both sides

With this program I'n trying achieve an output that looks something like this
A+B+C= 7
xMin = 3
xMax = 8
3----10
4----11
5----12
6----13
7----14
8----15
Instead I usually get something like this
4----0
5----0
6----0
7----0
8----0
It only changes when I hard code xMin or xMax to display, all the in-bewteens don't show.
#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int X = 0;
double a, b, c, xMin, xMax;
double y = 0;
cout << "#1(A): ";
cin >> a;
cout << "\n#2(B): ";
cin >> b;
cout << "\#3(C): ";
cin >> c;
cout << "Enter Xmin" << endl;
cin >> xMin;
cout << "Enter Xmax" << endl;
cin >> xMax;
y = a + b + c + X;
for (int count = xMin; count <= xMax; count++)
{
cout << count << "\t" << y << "\n";
}
return 0;
}
Your for loop is wrong (you are not updating the upper bound), change it to :
y = a + b + c;
for (int count = xMin; count <= xMax; count++)
{
cout << count << "\t" << count + y << "\n";
}
#include <iostream>
#include <cmath>
using namespace std;
struct updInt{
int xMax;
int xMin;
int inc;
int val;
bool flag;
friend ostream& operator<<(ostream& os, updInt& dt){
os <<dt.val;
dt.val+=dt.inc;
if(dt.val>dt.xMax)
dt.flag=true;
if(dt.val<dt.xMin)
dt.flag=true;
return os;
}
updInt(int a,updInt X,int inc=1){
this->val=a+X.val;
this->xMax = a + X.xMax;
this->xMin = a + X.xMin;
this->inc =inc;
flag=false;
}
updInt(int max,int min,int val,int inc=1){
this->val= val;
this->xMax = max;
this->xMin = min;
this->inc = inc;
flag=false;
}};
int main(){
int a, b, c, xMin, xMax;
cout << "#1(A): ";
cin >> a;
cout << "\n#2(B): ";
cin >> b;
cout << "\#3(C): ";
cin >> c;
cout << "Enter Xmin" << endl;
cin >> xMin;
cout << "Enter Xmax" << endl;
cin >> xMax;
updInt X(xMax,xMin,0);
updInt y(a + b + c , X);
for (int count = xMin; count <= xMax; count++)
{
cout << count << "\t" << y << "\n";
if(y.flag)
break;
}
return 0;
}
You need to write your ostream operator when you want to increase it without touching at the loop but i dunno why dont you simply increase y too.

How to simplify a fraction

I want to simplify a fraction in my application. The fraction is like,
x/y where x and y are integers.
I want to simplify the fraction to its simplest form.
Can anyone please give me hints how to do it.
Thanks in advance.
Compute the greatest common divisor for x and y
Divide both of them by the GCD
Euclid's algorithm is an easy way to compute the GCD.
Divide both by gcd(x,y)
The Binary GCD algorithm is a fast way to compute the GCD on a computer.
#include<iostream>
using namespace std;
struct fraction
{
int n1, d1, n2, d2, s1, s2;
};
void simplification(int a,int b)
{
bool e = true;
int t; int z;
for (int i = (a*b); i > 1;i--)
{ if ((a%i==0)&&(b%i==0))
{
t = a / i;
z = b / i;
}
else
{
e = false;
}
}
cout << "simplest form=" << t << "/" << z << endl;
}
void sum(int num1, int deno1, int num2, int deno2)
{
int k,y;
k = num1* deno2 + num2*deno1;
y = deno2*deno1;
cout << "addition of given fraction = " << k << "/" << y << endl;
simplification(k, y);
}
void sub(int num1, int deno1, int num2, int deno2)
{
int k, y;
k = num1*deno2 - num2*deno1;
y = deno1*deno2;
cout << "Substraction of given fraction = " << k << "/" << y << endl;
}
void mul(int num1, int deno1, int num2, int deno2)
{
int k, y;
k = num1*num2;
y = deno1*deno2;
cout << "multiplication of given fration= " << k<< "/" <<y; cout<< endl;
simplification(k, y);
}
void div(int num1, int deno1, int num2, int deno2)
{
int k, y;
;
k = num1*deno1;
y = deno1*num2;
cout << "division of given fraction" << k << "/" << y << endl;
simplification(k, y);
}
int main()
{ fraction a;
cout << "enter numirator of f1=";cin >> a.n1;
cout << "enter denominator of f1=";cin >> a.d1;
cout << "enter numirator of f2=";cin >> a.n2;
cout << "enter denominator of f2=";cin >> a.d2;
cout << "f1= " << a.n1 << "/" << a.d1 << endl;
cout << "f2= " << a.n2 << "/" << a.d2 << endl;
mul(a.n1, a.d1, a.n2, a.d2);
div(a.n1, a.d1, a.n2, a.d2);
sub(a.n1, a.d1, a.n2, a.d2);
sum(a.n1, a.d1, a.n2, a.d2);
system("pause");
}