AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Taschenrechner Programmieren

Ein Thema von Jack Ryan · begonnen am 16. Apr 2004 · letzter Beitrag vom 29. Sep 2004
Antwort Antwort
Seite 6 von 6   « Erste     456   
Benutzerbild von Wuaegner
Wuaegner

Registriert seit: 8. Feb 2004
406 Beiträge
 
Delphi 6 Enterprise
 
#51

Re: Taschenrechner Programmieren

  Alt 29. Sep 2004, 15:10
Dann zeig mal deinen ganzen Code, wie du Umwandeln deklarierst usw.
Wuaegner
Gruß Flo
Unternehmensberatung
  Mit Zitat antworten Zitat
Excalibur

Registriert seit: 24. Sep 2004
7 Beiträge
 
#52

Re: Taschenrechner Programmieren

  Alt 29. Sep 2004, 16:07
Is halt etwas lang geraten, wegen den vielen groß/klein-Möglichkeiten (und das sind nur die häufigsten)

Delphi-Quellcode:
unit wandler;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Edit2: TEdit;
    Edit3: TEdit;
    Label3: TLabel;
    Button1: TButton;
    Label4: TLabel;
    Label5: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var Eingabe, Ergebnis : real;
Einheit, Einheitneu:string;
begin
Eingabe:=strtoint(Edit1.text);
Einheit:=(Edit2.Text);
EInheitneu:=Edit3.Text;

If (lowercase(Einheit)='cm') and (lowercase(Ergebnis)='m')
then Ergebnis:=Eingabe /100;
If (Einheit='CM') and (einheitneu='m')
then Ergebnis:=Eingabe /100;
If (Einheit='Cm') and (einheitneu='m')
then Ergebnis:=Eingabe /100;
If (Einheit='cM') and (einheitneu='m')
then Ergebnis:=Eingabe /100;
If (Einheit='CM') and (einheitneu='M')
then Ergebnis:=Eingabe /100;
If (Einheit='cm') and (einheitneu='M')
then Ergebnis:=Eingabe /100;
If (Einheit='Cm') and (einheitneu='M')
then Ergebnis:=Eingabe /100;
If (Einheit='cM') and (einheitneu='M')
then Ergebnis:=Eingabe /100;

If (Einheit='m') and (einheitneu='cm')
then Ergebnis:=Eingabe *100;
If (Einheit='M') and (einheitneu='cm')
then Ergebnis:=Eingabe *100;
If (Einheit='m') and (einheitneu='Cm')
then Ergebnis:=Eingabe *100;
If (Einheit='m') and (einheitneu='cM')
then Ergebnis:=Eingabe *100;
If (Einheit='M') and (einheitneu='Cm')
then Ergebnis:=Eingabe *100;
If (Einheit='M') and (einheitneu='cM')
then Ergebnis:=Eingabe *100;
If (Einheit='M') and (einheitneu='CM')
then Ergebnis:=Eingabe *100;
If (Einheit='m') and (einheitneu='CM')
then Ergebnis:=Eingabe *100;

If (Einheit='DM') and (einheitneu='cm')
then Ergebnis:=Eingabe *10;
If (Einheit='DM') and (einheitneu='CM')
then Ergebnis:=Eingabe *10;
If (Einheit='DM') and (einheitneu='Cm')
then Ergebnis:=Eingabe *10;
If (Einheit='DM') and (einheitneu='cM')
then Ergebnis:=Eingabe *10;
If (Einheit='DM') and (einheitneu='CM')
then Ergebnis:=Eingabe *10;
If (Einheit='dm') and (einheitneu='CM')
then Ergebnis:=Eingabe *10;
If (Einheit='dm') and (einheitneu='Cm')
then Ergebnis:=Eingabe *10;
If (Einheit='dm') and (einheitneu='cM')
then Ergebnis:=Eingabe *10;
If (Einheit='dm') and (einheitneu='cm')
then Ergebnis:=Eingabe *10;

If (Einheit='cm') and (einheitneu='dm')
then Ergebnis:=Eingabe /10;
If (Einheit='CM') and (einheitneu='dm')
then Ergebnis:=Eingabe /10;
If (Einheit='cm') and (einheitneu='DM')
then Ergebnis:=Eingabe /10;
If (Einheit='Cm') and (einheitneu='Dm')
then Ergebnis:=Eingabe /10;
If (Einheit='cM') and (einheitneu='dM')
then Ergebnis:=Eingabe /10;
If (Einheit='CM') and (einheitneu='DM')
then Ergebnis:=Eingabe /10;
If (Einheit='cM') and (einheitneu='dm')
then Ergebnis:=Eingabe /10;
If (Einheit='Cm') and (einheitneu='dM')
then Ergebnis:=Eingabe /10;
If (Einheit='cM') and (einheitneu='Dm')
then Ergebnis:=Eingabe /10;

If (Einheit='M') and (einheitneu='dm')
then Ergebnis:=Eingabe *10;
If (Einheit='m') and (einheitneu='dm')
then Ergebnis:=Eingabe *10;
If (Einheit='M') and (einheitneu='DM')
then Ergebnis:=Eingabe *10;
If (Einheit='m') and (einheitneu='DD')
then Ergebnis:=Eingabe *10;
If (Einheit='M') and (einheitneu='dM')
then Ergebnis:=Eingabe *10;
If (Einheit='M') and (einheitneu='Dm')
then Ergebnis:=Eingabe *10;
If (Einheit='m') and (einheitneu='dM')
then Ergebnis:=Eingabe *10;
If (Einheit='m') and (einheitneu='Dm')
then Ergebnis:=Eingabe *10;

If (Einheit='m') and (einheitneu='mm')
then Ergebnis:=Eingabe *1000;
If (Einheit='M') and (einheitneu='mm')
then Ergebnis:=Eingabe *1000;
If (Einheit='m') and (einheitneu='MM')
then Ergebnis:=Eingabe *1000;
If (Einheit='m') and (einheitneu='mM')
then Ergebnis:=Eingabe *1000;
If (Einheit='m') and (einheitneu='Mm')
then Ergebnis:=Eingabe *1000;
If (Einheit='M') and (einheitneu='mM')
then Ergebnis:=Eingabe *1000;
If (Einheit='M') and (einheitneu='Mm')
then Ergebnis:=Eingabe *1000;
If (Einheit='M') and (einheitneu='MM')
then Ergebnis:=Eingabe *1000;

If (Einheit='km') and (einheitneu='mm')
then Ergebnis:=Eingabe *1000000;
If (Einheit='KM') and (einheitneu='MM')
then Ergebnis:=Eingabe *1000000;
If (Einheit='Km') and (einheitneu='Mm')
then Ergebnis:=Eingabe *1000000;
If (Einheit='kM') and (einheitneu='MM')
then Ergebnis:=Eingabe *1000000;
If (Einheit='kM') and (einheitneu='mM')
then Ergebnis:=Eingabe *1000000;
If (Einheit='Km') and (einheitneu='mm')
then Ergebnis:=Eingabe *1000000;
If (Einheit='kM') and (einheitneu='mm')
then Ergebnis:=Eingabe *1000000;
If (Einheit='Km') and (einheitneu='Mm')
then Ergebnis:=Eingabe *1000000;

If (Einheit='km') and (einheitneu='m')
then Ergebnis:=Eingabe *1000;
If (Einheit='KM') and (einheitneu='M')
then Ergebnis:=Eingabe *1000;
If (Einheit='km') and (einheitneu='M')
then Ergebnis:=Eingabe *1000;
If (Einheit='kM') and (einheitneu='M')
then Ergebnis:=Eingabe *1000;
If (Einheit='Km') and (einheitneu='m')
then Ergebnis:=Eingabe *1000;
If (Einheit='KM') and (einheitneu='m')
then Ergebnis:=Eingabe *1000;
If (Einheit='kM') and (einheitneu='m')
then Ergebnis:=Eingabe *1000;

If (Einheit='mm') and (einheitneu='km')
then Ergebnis:=Eingabe /1000000;
usw

Label5.caption:=floattostr (Ergebnis)+(Einheitneu);

end;

end.
Die 10 Gebote zählen 279 Wörter, die Unabhängigkeitserklärung der 13 nordamerikanischen Staaten 1776 zählt 300 Wörter, die EU-Verordnung über den Import von Karamel-Bonbons 1981 besteht aus 25 911 Wörtern.
  Mit Zitat antworten Zitat
Benutzerbild von JasonDX
JasonDX
(CodeLib-Manager)

Registriert seit: 5. Aug 2004
Ort: München
1.062 Beiträge
 
#53

Re: Taschenrechner Programmieren

  Alt 29. Sep 2004, 16:19
ich hab mir nicht die ganze diskussion durchgelesen, aber mal 'n kleiner tipp, wie du den Code 'n bissl übersichtlich machen könntst:
versuch mal, mit
UpperCase() die ganzen IFs mit dem 'CM', 'cm', 'Cm', 'cM'.... wegzuräumen!
Mike
Passion is no replacement for reason
  Mit Zitat antworten Zitat
Benutzerbild von alcaeus
alcaeus

Registriert seit: 11. Aug 2003
Ort: München
6.537 Beiträge
 
#54

Re: Taschenrechner Programmieren

  Alt 29. Sep 2004, 16:22
Hi Excalibur,

If (lowercase(Einheit)='cm') and (lowercase(Ergebnis)='m') Hier liegt der Fehler. Die Richtige Variable müsste Einheitneu, und nicht Ergebnis heißen. Jedenfalls verwendest du später immer wieder Einheitneu..

Greetz
alcaeus
Andreas B.
Die Mutter der Dummen ist immer schwanger.
Ein Portal für Informatik-Studenten: www.infler.de
  Mit Zitat antworten Zitat
Benutzerbild von Wuaegner
Wuaegner

Registriert seit: 8. Feb 2004
406 Beiträge
 
Delphi 6 Enterprise
 
#55

Re: Taschenrechner Programmieren

  Alt 29. Sep 2004, 18:41
HI Excalibur!
Zitat:
Quellcode: markieren
If (lowercase(Einheit)='cm') and (lowercase(Ergebnis)='m')


Hier liegt der Fehler. Die Richtige Variable müsste Einheitneu, und nicht Ergebnis heißen. Jedenfalls verwendest du später immer wieder Einheitneu..
Genau, da Ergebnis vom Typ Real ist , die Funktion lowercase() aber einen String braucht und keinen Real kommt die Fehlermeldung.
Wuaegner
Gruß Flo
Unternehmensberatung
  Mit Zitat antworten Zitat
Excalibur

Registriert seit: 24. Sep 2004
7 Beiträge
 
#56

Re: Taschenrechner Programmieren

  Alt 29. Sep 2004, 18:45
aber da kommt immernoch: Inkompatible Typen: 'String' und 'Real'
-> ich muss des erst noch umwandeln, aber wie und wo muss des hin?
Die 10 Gebote zählen 279 Wörter, die Unabhängigkeitserklärung der 13 nordamerikanischen Staaten 1776 zählt 300 Wörter, die EU-Verordnung über den Import von Karamel-Bonbons 1981 besteht aus 25 911 Wörtern.
  Mit Zitat antworten Zitat
Benutzerbild von alcaeus
alcaeus

Registriert seit: 11. Aug 2003
Ort: München
6.537 Beiträge
 
#57

Re: Taschenrechner Programmieren

  Alt 29. Sep 2004, 18:59
Hi Excalibur,

Hier mal ein Auszug aus deinem Code:
Delphi-Quellcode:
If (lowercase(Einheit)='cm') and (lowercase(Ergebnis)='m')
then Ergebnis:=Eingabe /100;
If (Einheit='CM') and (einheitneu='m')
then Ergebnis:=Eingabe /100;
If (Einheit='Cm') and (einheitneu='m')
then Ergebnis:=Eingabe /100;
If (Einheit='cM') and (einheitneu='m')
then Ergebnis:=Eingabe /100;
If (Einheit='CM') and (einheitneu='M')
then Ergebnis:=Eingabe /100;
If (Einheit='cm') and (einheitneu='M')
then Ergebnis:=Eingabe /100;
If (Einheit='Cm') and (einheitneu='M')
then Ergebnis:=Eingabe /100;
If (Einheit='cM') and (einheitneu='M')
then Ergebnis:=Eingabe /100;
Du verwendest in den einzelnen if-Abfragen Einheit und Einheitneu, und anschließend rechnest du das ergebnis aus. Also musst du auch im lowercase-teil Einheit und Einheitneu verwenden. So kompliziert dürfte das wohl nicht sein

Greetz
alcaeus
Andreas B.
Die Mutter der Dummen ist immer schwanger.
Ein Portal für Informatik-Studenten: www.infler.de
  Mit Zitat antworten Zitat
Benutzerbild von Wuaegner
Wuaegner

Registriert seit: 8. Feb 2004
406 Beiträge
 
Delphi 6 Enterprise
 
#58

Re: Taschenrechner Programmieren

  Alt 29. Sep 2004, 19:04
Code:
procedure TForm1.Button1Click(Sender: TObject);
var Eingabe, Ergebnis : real;
Einheit, Einheitneu:string;
begin
Eingabe:=strto[size=18]float[/size]('17');
Einheit:='CM';
EInheitneu:='M';

If (lowercase(Einheit)='cm') and (lowercase(EinheitNeu)='m')
then Ergebnis:=Eingabe /100;
So geht's.
Wuaegner
Gruß Flo
Unternehmensberatung
  Mit Zitat antworten Zitat
Benutzerbild von Nothine
Nothine

Registriert seit: 3. Jul 2004
Ort: Mülheim an der Ruhr
198 Beiträge
 
Delphi 5 Enterprise
 
#59

Re: Taschenrechner Programmieren

  Alt 29. Sep 2004, 19:18
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var Eingabe,Ergebnis: Real;
    Einheit,EinheitNeu: string;
begin
  Eingabe := StrToFloat(Edit1.Text); //StrToFLOAT !
  Einheit := Edit2.Text;
  EinheitNeu := Edit3.Text;
  Ergebnis := 0;

  if (UpperCase(Einheit)='CM') and (UpperCase(EinheitNeu)='DM') then
    Ergebnis := Eingabe / 10;
  if (UpperCase(Einheit)='CM') and (UpperCase(EinheitNeu)='M') then
    Ergebnis := Eingabe / 100;
  if (UpperCase(Einheit)='MM') and (Uppercase(EinheitNeu)='KM') then
    Ergebnis := Eingabe / 1000000;
  if (UpperCase(Einheit)='DM') and (UpperCase(EinheitNeu)='CM') then
    Ergebnis := Eingabe * 10;
  if (UpperCase(Einheit)='M') and (UpperCase(EinheitNeu)='DM') then
    Ergebnis := Eingabe * 10;
  if (UpperCase(Einheit)='M') and (UpperCase(EinheitNeu)='CM') then
    Ergebnis := Eingabe * 100;
  if (UpperCase(Einheit)='M') and (UpperCase(EinheitNeu)='MM') then
    Ergebnis := Eingabe * 1000;
  if (UpperCase(Einheit)='KM') and (UpperCase(EinheitNeu)='M') then
    Ergebnis := Eingabe * 1000;
  if (UpperCase(Einheit)='KM') and (UpperCase(EinheitNeu)='MM') then
    Ergebnis := Eingabe * 1000000;

  Label5.Caption := FloatToStr(Ergebnis) + EinheitNeu;
end;
so sollte deine button-prozedur aussehen... (abgesehn davon dass noch nicht alle kombinationen drin sind )

//Edit: und das mit UpperCase und LowerCase is reine geschmackssache...
if ThisPost is senseless then
ThisPost.WasPostedBy := SomeoneElse();
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 6 von 6   « Erste     456   


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:29 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz