Quando clico em qualquer um dos botões aparece uma janela escrito "An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: A cadeia de caracteres de entrada não estava em um formato correto." na linha "double valorSaque = Convert.ToDouble(textoDoValorDoSaque);" Alguém pode me ajudar? ´´´ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;
namespace CaixaEletronico { public partial class Form1 : Form { Conta conta; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { Conta conta = new Conta(); conta.Titular = new Cliente(); conta.Titular.Nome = "Victor"; conta.Numero = 1; conta.Deposita(250.0);
textTitular.Text = conta.Titular.Nome; textNumero.Text = Convert.ToString(conta.Numero); textSaldo.Text = Convert.ToString(conta.Saldo);
}
private void button1_Click(object sender, EventArgs e) { string textoDoValorDoDeposito = textValor.Text; double valorDeposito = Convert.ToDouble(textoDoValorDoDeposito); this.conta.Deposita(valorDeposito);
textTitular.Text = conta.Titular.Nome; textNumero.Text = Convert.ToString(conta.Numero); textSaldo.Text = Convert.ToString(conta.Saldo);
}
private void button2_Click(object sender, EventArgs e) { string textoDoValorDoSaque = textValor.Text;
double valorSaque = Convert.ToDouble(textoDoValorDoSaque); this.conta.Saca(valorSaque);
textTitular.Text = conta.Titular.Nome; textNumero.Text = Convert.ToString(conta.Numero); textSaldo.Text = Convert.ToString(conta.Saldo); } } } ´´´ ´´´ namespace CaixaEletronico { partial class Form1 { /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null;
/// /// Clean up any resources being used. /// ///
true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); }region Windows Form Designer generated code
/// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.textTitular = new System.Windows.Forms.TextBox(); this.textSaldo = new System.Windows.Forms.TextBox(); this.textNumero = new System.Windows.Forms.TextBox(); this.textValor = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // textTitular // this.textTitular.Location = new System.Drawing.Point(124, 53); this.textTitular.Name = "textTitular"; this.textTitular.Size = new System.Drawing.Size(100, 20); this.textTitular.TabIndex = 0; this.textTitular.Text = "Titular :"; // // textSaldo // this.textSaldo.Location = new System.Drawing.Point(124, 79); this.textSaldo.Name = "textSaldo"; this.textSaldo.Size = new System.Drawing.Size(100, 20); this.textSaldo.TabIndex = 1; this.textSaldo.Text = "Saldo: "; // // textNumero // this.textNumero.Location = new System.Drawing.Point(124, 105); this.textNumero.Name = "textNumero"; this.textNumero.Size = new System.Drawing.Size(100, 20); this.textNumero.TabIndex = 2; this.textNumero.Text = "Numero: "; // // textValor // this.textValor.Location = new System.Drawing.Point(124, 131); this.textValor.Name = "textValor"; this.textValor.Size = new System.Drawing.Size(100, 20); this.textValor.TabIndex = 4; this.textValor.Text = "Valor:"; // // button1 // this.button1.Location = new System.Drawing.Point(135, 191); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 5; this.button1.Text = "Depositar"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // this.button2.Location = new System.Drawing.Point(43, 191); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(75, 23); this.button2.TabIndex = 6; this.button2.Text = "Sacar"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // Form1 // this.ClientSize = new System.Drawing.Size(284, 261); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Controls.Add(this.textValor); this.Controls.Add(this.textNumero); this.Controls.Add(this.textSaldo); this.Controls.Add(this.textTitular); this.Name = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); this.PerformLayout();
}
endregion
private System.Windows.Forms.TextBox textTitular; private System.Windows.Forms.TextBox textSaldo; private System.Windows.Forms.TextBox textNumero; private System.Windows.Forms.TextBox textValor; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; } } ´´´ ´´´ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace CaixaEletronico { class Conta { public int Numero { get; set; } public Cliente Titular { get; set; } public double Saldo { get; private set; }
//atributos agencias e cpf omitidos
public void Deposita(double valorASerDepositado) { if (valorASerDepositado >= 0) { this.Saldo += valorASerDepositado; } }
public void Saca(double valorASerSacado) { if (valorASerSacado < this.Saldo || valorASerSacado > 0) { this.Saldo += valorASerSacado; }
}
public void Transfere(double valor, Conta destino) { this.Saca(valor); destino.Deposita(valor); }
public double CalculaRendimentoAnual() { double saldoNaqueleMes = this.Saldo;
for (int i = 0; i < 12; i++) { saldoNaqueleMes = saldoNaqueleMes * 1.007; }
double rendimento = saldoNaqueleMes - this.Saldo;
return rendimento; } } }
´´´ ´´´ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace CaixaEletronico { class Cliente { public string Nome { get; set; } public Cliente(string nome) { this.Nome = nome; } public Cliente() { }//pq o nome é opcional public string rg; public string cpf; public string endereco; public int idade;
public bool EhMaiorDeIdade() { return this.idade >= 18; } } } ´´´