0
If anyone can give me a detailed description, thank you, I’m new to the language
import 'dart:io';
void main(){
var saldo = 100;
print(' ');
print('gostaria de sacar dinheiro?: (y/n)');
String escolha = stdin.readLineSync();
if (escolha =='y' || escolha =='Y'){
print('seu saldo é $saldo reais.');
print('quanto gostaria de sacar?');
dynamic saque = stdin.readLineSync();
saque = int.parse(saque);
if(saque <=saldo){
print('seu saque de $saque reais foi realizado com sucesso!');
dynamic saldo_novo = saldo - saque;
print('novo saldo: $saldo_novo');
} else{
print('saldo insuficiente para realizar a operação');
}
}
if (escolha == 'n' || escolha == 'N'){
print('seu saldo não foi alterado');
}
print('----------------------');
print('finalizando programa...');
}
Error message
#0 int._throwFormatException (dart:core-patch/integers_patch.dart:133:5) #1 int._parseRadix (dart:core-patch/integers_patch.dart:144:16) #2 int._parse (dart:core-patch/integers_patch.dart:102:12) #3 int.parse (dart:core-patch/integers_patch.dart:65:12) #4 main (file:///C:/Users/Allen/Documents/Dart%20things/funcoes.dart:11:17) #5 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:307:19) #6 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
the fact that I use Dynamics, doesn’t adjust the variable for me? or just tell me that I can change the value and type?
– Allen Rodger
got it, I thought that automatically the input would be a string like python, and needed to convert.
– Allen Rodger
gave the following error: Error: A value of type 'String' can’t be Assigned to a variable of type 'double'. as I believe that just like python, an input is naturally a string
– Allen Rodger
Oops, sorry, I forgot that question, I’ll adjust the answer.
– Matheus Ribeiro
See the answer again, I’m not being able to test it now, but I believe that a
toDouble()
should solve.– Matheus Ribeiro
I made a small test with the Dart:core library import, but toDouble appears as undefined.
– Allen Rodger
Look at my answer, I put the modification wrong, and then I set it right, so it should be all right.
– Matheus Ribeiro