So I am currently writing a program that asks the user for the degree of the polynomial they will be multiplying and then will multiply said polynomial. My program is set to only multiply up to the third polynomial. I use an if statement to check the degree, and then prompt the user for the number of coefficients needed. However, I have another if statement further in the program that uses these coefficients and assigns them to the product polynomial's coefficients. It says that I can't use the variable as it may have not been initialized?? I declared the variables all at the beginning of the code, not within the if statements but it still says it may have not been initialized. I'll include the code below. Any help would be appreciated!
if (degreeform == 1)
{
degreeformstate = true;
coef_A = conIO.promptForInt("Enter coefficient a: ");
conIO.printEndline();
coef_B = conIO.promptForInt("Enter coefficient b: ");
conIO.printEndline();
coef_C = conIO.promptForInt("Enter coefficient c: ");
conIO.printEndline();
coef_D = conIO.promptForInt("Enter coefficient d: ");
conIO.printEndlines(TWO_ENDLINES);
}
else if (degreeform == 2)
{
degreeformstate = true;
coef_A = conIO.promptForInt("Enter coefficient a: ");
conIO.printEndline();
coef_B = conIO.promptForInt("Enter coefficient b: ");
conIO.printEndline();
coef_C = conIO.promptForInt("Enter coefficient c: ");
conIO.printEndline();
coef_D = conIO.promptForInt("Enter coefficient d: ");
conIO.printEndline();
coef_E = conIO.promptForInt("Enter coefficient e: ");
conIO.printEndlines(TWO_ENDLINES);
}
else if (degreeform == 3)
{
degreeformstate = true;
coef_A = conIO.promptForInt("Enter coefficient a: ");
conIO.printEndline();
coef_B = conIO.promptForInt("Enter coefficient b: ");
conIO.printEndline();
coef_C = conIO.promptForInt("Enter coefficient c: ");
conIO.printEndline();
coef_D = conIO.promptForInt("Enter coefficient d: ");
conIO.printEndline();
coef_E = conIO.promptForInt("Enter coefficient e: ");
conIO.printEndline();
coef_F = conIO.promptForInt("Enter coefficient f: ");
conIO.printEndlines(TWO_ENDLINES);
}
else
{
degreeformstate = false;
conIO.printString("Incorrect number of polynomial degrees entered - Program Aborted");
System.exit(0);
}
if (degreeform == 1)
{
coef_V = coef_A * coef_C;
coef_W = (coef_B * coef_C) + (coef_A * coef_D);
coef_X = (coef_B * coef_D);
}
// polynomial type 2
else if (degreeform == 2)
{
coef_V = coef_A * coef_C;
coef_W = (coef_B * coef_C) + (coef_A * coef_D);
coef_X = (coef_A * coef_E) + (coef_B * coef_D);
coef_Y = coef_B * coef_E;
}
// polynomial type 3
else
{
coef_V = coef_A * coef_C;
coef_W = (coef_B * coef_C) + (coef_A * coef_D);
coef_X = (coef_A * coef_E) + (coef_B * coef_D);
coef_Y = (coef_A * coef_F)+ (coef_B * coef_E);
coef_Z = coef_B * coef_E;
}
Aucun commentaire:
Enregistrer un commentaire