Autor Beitrag
storestore
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 397
Erhaltene Danke: 7

WIN 7
C#
BeitragVerfasst: Do 01.09.11 13:55 
Hallo,
ich bins wieder .,. ,
ich bin dabei c# zu lernen und deswegen dachte ich mir ich will mal meine Kentnisse testen und nciht immer nur im Buch lesen!
Ich habe folgendes Problem:
Wenn ich bei der Consolen anwendung 'D' eingebe, dann ist alles ok. Er Fürht die Anweisung wie in der If- Anweisung aus. Aber wenn ich 'A' eingebe dann beendet er einfach das Programm.
Ich weiß echt nicht mehr weiter :(
Hier ist mal der quellencode
ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hallo, geben sie bitte ihr aktuelles Guthaben ein!");
            double geld = Convert.ToDouble(Console.ReadLine());
            Console.ReadLine();
            Console.WriteLine("Wollen sie was drauf zahlen oder abziehen?");
            Console.WriteLine("D= draufzahlen, A=Abziehen!");
            if (Console.ReadLine() == "D")
            {
                Console.WriteLine("Wie viel wollen sie drauf zahlen?");
                double draufzahlen = Convert.ToDouble(Console.ReadLine());
                geld = geld + draufzahlen;
                Console.WriteLine("Ihr aktuelles Guthaben= " + geld);
                Console.ReadLine();
            }
            else
            {
                if (Console.ReadLine() == "A")
                {
                    Console.WriteLine("Wie viel wollen sie abheben?");
                    double abheben = Convert.ToDouble(Console.ReadLine());
                    Console.ReadLine();
                    geld = geld + abheben;
                    Console.WriteLine("Ihr aktuelles Guthaben= " + geld);
                    Console.ReadLine();
                }
            }
        }
    }
}



mfg storestroe

Moderiert von user profile iconTh69: Titel geändert.

_________________
Der Pc ist nur so schlau, wie derjenige der in steuert!
"Don't Quit. Suffer now, and live the rest of your life as a champion"
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4799
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Do 01.09.11 14:07 
Hallo storestore,

hast du schon den Debugger genutzt?
Dann würdest du sehen, daß er nach der ersten Eingabe (von "A") in der Zeile
ausblenden C#-Quelltext
1:
if (Console.ReadLine() == "A")					

stehen bleibt (bzw. müsste ;-))

Du wartest also zweimal auf das Eingeben einer Zeile.
Alternative wäre die Rückgabe von ReadLine() in einer eigenen Variablen zu speichern oder aber eine switch-case-Anweisung...

P.S: Kannst du deinen eigenen Namen nicht mehr schreiben? :SCNR:

Für diesen Beitrag haben gedankt: storestore
mats74
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 189
Erhaltene Danke: 26

Win 10
VS 2017/19, C++, C#
BeitragVerfasst: Do 01.09.11 14:17 
Hallo storestore

Ich würde den Konsolenwert in einer Variable speichern und danach die If-Anweisung entsprechend setzen:

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hallo, geben sie bitte ihr aktuelles Guthaben ein!");
            double geld = Convert.ToDouble(Console.ReadLine());
            Console.ReadLine();
            Console.WriteLine("Wollen sie was drauf zahlen oder abziehen?");
            Console.WriteLine("D= draufzahlen, A=Abziehen!");
            string text = Console.ReadLine();
            if (text == "D")
            {
                Console.WriteLine("Wie viel wollen sie drauf zahlen?");
                double draufzahlen = Convert.ToDouble(Console.ReadLine());
                geld = geld + draufzahlen;
                Console.WriteLine("Ihr aktuelles Guthaben= " + geld);
                Console.ReadLine();
            }
            else if (text == "A")
            {
                Console.WriteLine("Wie viel wollen sie abheben?");
                double abheben = Convert.ToDouble(Console.ReadLine());
                geld = geld - abheben;
                Console.WriteLine("Ihr aktuelles Guthaben= " + geld);
                Console.ReadLine();
            }
            else
            {
            }
        }
    }


Kleiner Fehler noch beim "abheben" (+/-).

Gruss
mats74

Für diesen Beitrag haben gedankt: storestore
storestore Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 397
Erhaltene Danke: 7

WIN 7
C#
BeitragVerfasst: Do 01.09.11 14:34 
user profile iconTh69 hat folgendes geschrieben Zum zitierten Posting springen:
Hallo storestore,

hast du schon den Debugger genutzt?
Dann würdest du sehen, daß er nach der ersten Eingabe (von "A") in der Zeile
ausblenden C#-Quelltext
1:
if (Console.ReadLine() == "A")					

stehen bleibt (bzw. müsste ;-))

Du wartest also zweimal auf das Eingeben einer Zeile.
Alternative wäre die Rückgabe von ReadLine() in einer eigenen Variablen zu speichern oder aber eine switch-case-Anweisung...

P.S: Kannst du deinen eigenen Namen nicht mehr schreiben? :SCNR:


Hallo, also der debugger gibt mir keinen Fehler und das mit dem Namen war nur ausversehen. Das zeigt aber das ich ein Mensch bin

mfg storestore
Editt:

user profile iconmats74 hat folgendes geschrieben Zum zitierten Posting springen:
Hallo storestore

Ich würde den Konsolenwert in einer Variable speichern und danach die If-Anweisung entsprechend setzen:

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hallo, geben sie bitte ihr aktuelles Guthaben ein!");
            double geld = Convert.ToDouble(Console.ReadLine());
            Console.ReadLine();
            Console.WriteLine("Wollen sie was drauf zahlen oder abziehen?");
            Console.WriteLine("D= draufzahlen, A=Abziehen!");
            string text = Console.ReadLine();
            if (text == "D")
            {
                Console.WriteLine("Wie viel wollen sie drauf zahlen?");
                double draufzahlen = Convert.ToDouble(Console.ReadLine());
                geld = geld + draufzahlen;
                Console.WriteLine("Ihr aktuelles Guthaben= " + geld);
                Console.ReadLine();
            }
            else if (text == "A")
            {
                Console.WriteLine("Wie viel wollen sie abheben?");
                double abheben = Convert.ToDouble(Console.ReadLine());
                geld = geld - abheben;
                Console.WriteLine("Ihr aktuelles Guthaben= " + geld);
                Console.ReadLine();
            }
            else
            {
            }
        }
    }


Kleiner Fehler noch beim "abheben" (+/-).

Gruss
mats74


Danke, dann muss ich das eine Console.Readline(); weglassen. Das mit dem +/- ist mir auch schon aufgefallen. Wie regle ich das am besten. Also an der Variable duble liegt es schonmal nicht!

mfg storestore

_________________
Der Pc ist nur so schlau, wie derjenige der in steuert!
"Don't Quit. Suffer now, and live the rest of your life as a champion"
mats74
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 189
Erhaltene Danke: 26

Win 10
VS 2017/19, C++, C#
BeitragVerfasst: Do 01.09.11 14:43 
Hallo storestore

Zitat:
Wie regle ich das am besten. Also an der Variable duble liegt es schonmal nicht!


Also bei mir funktioniert der Code tip top.
Was willst Du den noch genau regeln?

Gruss
mats74

Für diesen Beitrag haben gedankt: storestore
storestore Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 397
Erhaltene Danke: 7

WIN 7
C#
BeitragVerfasst: Do 01.09.11 14:49 
user profile iconmats74 hat folgendes geschrieben Zum zitierten Posting springen:
Hallo storestore

Zitat:
Wie regle ich das am besten. Also an der Variable duble liegt es schonmal nicht!


Also bei mir funktioniert der Code tip top.
Was willst Du den noch genau regeln?

Gruss
mats74

Naja das wenn ich jetzt guthaben 100 angebe und 200 abziehe dann zeigt er mir an das ich noch 100 habe aber nicht das es minus 100 sind

_________________
Der Pc ist nur so schlau, wie derjenige der in steuert!
"Don't Quit. Suffer now, and live the rest of your life as a champion"
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Do 01.09.11 14:57 
user profile iconstorestore hat folgendes geschrieben Zum zitierten Posting springen:
Naja das wenn ich jetzt guthaben 100 angebe und 200 abziehe dann zeigt er mir an das ich noch 100 habe aber nicht das es minus 100 sind

Also der Code im Beitrag von user profile iconmats74 funktioniert bei mir, er zeigt -100 an, wenn ich von 100 200 abziehe. Wie sieht denn dein Quelltext aus?

Für diesen Beitrag haben gedankt: storestore
storestore Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 397
Erhaltene Danke: 7

WIN 7
C#
BeitragVerfasst: Do 01.09.11 15:34 
Achso,ok danke passt schon. Ich hatte das minus übersehen :oops:

Danke für eure Hilfe.
mfg storestore

PS: Hättet ihr noch vorschläge für die Verbesserung oder muss ich dafür das Thema in dem bereich der Freeware öffnen?

_________________
Der Pc ist nur so schlau, wie derjenige der in steuert!
"Don't Quit. Suffer now, and live the rest of your life as a champion"
dark-destination1988
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 178
Erhaltene Danke: 21



BeitragVerfasst: Do 01.09.11 15:36 
kannst ja noch zinsen und laufzeit eingeben lassen und dann die Zinsen zum kontostand hinzurechnen

Für diesen Beitrag haben gedankt: storestore
bakachan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 503
Erhaltene Danke: 34

W7 (x64) Ultimate
C# / VB.NET (VS2010 Ultimate)
BeitragVerfasst: Do 01.09.11 15:39 
Wie wäre es erstmal wenn das Programm nicht endet nachdem man einmal eingezahlt/abgehoben hat?
storestore Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 397
Erhaltene Danke: 7

WIN 7
C#
BeitragVerfasst: Do 01.09.11 15:40 
user profile icondark-destination1988 hat folgendes geschrieben Zum zitierten Posting springen:
kannst ja noch zinsen und laufzeit eingeben lassen und dann die Zinsen zum kontostand hinzurechnen

Hi,
ok das mit den zinsen ist eine gute Idee. Aber das mit der Laufzeit verstehe ich nicht ganz. Was genau meinstu du als Lauftzeit.Meinst du die Laufzeit eines Kredites oder was? Hab erst seit einem Jahr BWR an der Schule ;)
Editt: Ich habe mir noch überlegt die ergebniss mit einem Streamwriter zu speichern und beim nächsten offnen es mit einem Streamreader wieder auszugeben.

_________________
Der Pc ist nur so schlau, wie derjenige der in steuert!
"Don't Quit. Suffer now, and live the rest of your life as a champion"
dark-destination1988
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 178
Erhaltene Danke: 21



BeitragVerfasst: Do 01.09.11 15:52 
naja beispielsweise, du hast in deiner ersten frage die auswahlmöglichkeit--> warten
gibst dort die anzahl der zinsen und die zeit die vergeht
-->bsp
du hast 100 euro
gehst auf warten gibst 1 % und 2 jahre ein
dann kriegst du 102,01 Euro raus
(aufpassen 1 jahr vorbei 101 euro--> zweites jahr 1% von 101 Euro!)

Für diesen Beitrag haben gedankt: storestore
storestore Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 397
Erhaltene Danke: 7

WIN 7
C#
BeitragVerfasst: Do 01.09.11 15:55 
Hmm, ok das wäre cool. Dann mache ich so eine art Simulation drauß. Danke für den tollen Tipp oh bei 1% von 101 euro muss man echt aupassen!

lg storestore

_________________
Der Pc ist nur so schlau, wie derjenige der in steuert!
"Don't Quit. Suffer now, and live the rest of your life as a champion"