Home > database >  how to show full results for X in double (for e.g X=3.45)?
how to show full results for X in double (for e.g X=3.45)?

Time:10-03

I had made this code to resolve an equation which X is unknown (Ax B = 0) it's working fine; but cannot show full results for X in double (for e.g X=3.45) value how can I do it thank you for your help

import 'dart:io' show stdin;
import 'dart:core' show FormatException, num, print;
import 'dart:math' show Random;

void main() {
for(var i=0 ; i<1 ; i--) {
  try {
    print("Equation N° 1 : ax b=0");
    print("Enter value of A");
    var a = stdin.readLineSync();
    var A = num.parse(a!);
    print("Enter value of B");
    var b = stdin.readLineSync();
    var B = num.parse(b!);
    var X;
    if (B != 0) {
      if (A != 0) {
        print("A = $A");
        print("B = $B");
        X = -B ~/ A;
        print("X=$X");
      } else if (A == 0) {
        print(A);
        print(B);
        print("The equation, does not admit a solution.");
        print("X = No solution ");
      }
    } else {
      if (A != 0) {
        print(A);
        print(B);
        print("the equation, admit 0 for solution");
        print("X = 0");
      } else {
        print(A);
        print(B);
        print("the equation, admits an infinity of solutions");
        print("X =  ∞");
      }
    }
  }
  on FormatException {
    print("Invalid Value");
    print("Please Entre a Valid Value");
  }
}
  }

CodePudding user response:

You are using the integer division : X = -B ~/ A
Try without the ~ symbol.
A & B should be double type and X as well

CodePudding user response:

remove the ~ symbol in X = -B ~/ A. and it will work fine

  • Related