Autor Beitrag
vit30
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 38



BeitragVerfasst: Mi 27.01.10 00:07 
Hallo!
Ich habe folgende Frage:
1.Was habe ich falsch geschrieben ("switch"-Bereich) beim aufrufen Methode "Add"? Compiller schreibt:"Der Name "resultAdd" ist im aktuellen Kontext nicht vorhanden."
2. Zweite Fehler: "ungültiges Token switch.." und "ungültiges Token break...". Was ist hier falsch?

Es sollte eigentlich ein taschenrechner sein(noch nicht ganz fertig).
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:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmalComp
{
class Program
{
static void Main(string[] args)
{}
#region methods
private float Add(float firstValue,float secondValue)
{
float resultAdd = firstValue + secondValue;return resultAdd;
}
private float Substrah(float fistValue,float secondValue)
{
}
private float Multiply(float firstValue, float secondValue)
{
}
private float Divide(float firstValue, float secondValue)
{
}
#endregion

///<summary>Hier werden die Zahlen eingegeben, die berechnet
///werden müssen.
///</summary>
private float addfirstValue(float firstValue)
{
Console.WriteLine("The first Small Computer from *lieber Vitalij*");
Console.WriteLine("Geben Sie erste Zahl ein:");
string a = Console.ReadLine();
return float.Parse(a);
}
private float addSecondvalue(float secondValue)
{
Console.WriteLine("Geben Sie zweite Zahl ein:");
string b = Console.ReadLine();
return float.Parse(b);

}
/// <summary>
/// Auswahl von Rechnenfunktion
/// </summary>
/// <param name="firstValue"></param>
/// <param name="secondValue"></param>
/// <returns></returns>
//try
// {
private int makeChoise(int choise)
{
Console.WriteLine("Für Addieren drücken Sie die 1","\r\n");
Console.WriteLine("Für Substrahieren drücken Sie 2","\r\n");
Console.WriteLine("Fur Multiplizieren drücken Sie 3","\r\n");
Console.WriteLine("Für Dividieren drücken Sie 4","\r\n");
//string Achoise = Console.ReadLine();
int choiseline = int.Parse(Console.ReadLine());
return choiseline;

}
switch (choise)
{
case 1 :
//Aufruf Methode Add
float endResult = Add(resultAdd);
break;
case 2 :
//Aufruf Methode Substrah
break;
case 3 :
//Aufruf Methode Multiply
break;
case 4 :
//Aufruf Methode Divide
break;
default :

break;
}

//catch { }


}


Moderiert von user profile iconChristian S.: C#-Tag korrigiert
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 27.01.10 00:17 
Rück mal Deinen Code korrekt ein, dann siehst Du den Fehler wahrscheinlich selber :-)

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
vit30 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 38



BeitragVerfasst: Mi 27.01.10 00:28 
user profile iconChristian S. hat folgendes geschrieben Zum zitierten Posting springen:
Rück mal Deinen Code korrekt ein, dann siehst Du den Fehler wahrscheinlich selber :-)

Ich sehe aber nicht :oops:
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 27.01.10 00:49 
Wie sieht Dein Code denn eingerückt aus?

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
vit30 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 38



BeitragVerfasst: Mi 27.01.10 10:44 
So sieht eingerückte Code aus.
Rufe ich Methode "Add" richtig auf?

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:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmalComp
{
    class Program
    {
        static void Main(string[] args)
        {}
#region methods
        private float Add(float firstValue,float secondValue)
        {
            float resultAdd = firstValue + secondValue;return resultAdd;
        }
        private float Substrah(float fistValue,float secondValue)
        {
        }
        private float Multiply(float firstValue, float secondValue) 
        {
        }
        private float Divide(float firstValue, float secondValue) 
        {
        }
#endregion   
       
        ///<summary>Hier werden die Zahlen eingegeben, die berechnet
        ///werden müssen.
        ///</summary>
        private float addfirstValue(float firstValue)
        {
            Console.WriteLine("The first Small Computer from *lieber Vitalij*");
            Console.WriteLine("Geben Sie erste Zahl ein:");
            string a = Console.ReadLine();
            return float.Parse(a);
        }
        private  float addSecondvalue(float secondValue)
        { 
            Console.WriteLine("Geben Sie zweite Zahl ein:");
            string b = Console.ReadLine();
            return float.Parse(b); 

        }
        /// <summary>
        /// Auswahl von Rechnenfunktion
        /// </summary>
        /// <param name="firstValue"></param>
        /// <param name="secondValue"></param>
        /// <returns></returns>
        //try
   // {
        private int makeChoise(int choise)
        {
            Console.WriteLine("Für Addieren drücken Sie die 1","\r\n");
            Console.WriteLine("Für Substrahieren drücken Sie 2","\r\n");
            Console.WriteLine("Fur Multiplizieren drücken Sie 3","\r\n");
            Console.WriteLine("Für Dividieren drücken Sie 4","\r\n");
            //string Achoise = Console.ReadLine();
            int choiseline = int.Parse(Console.ReadLine());
            return choiseline;
               
        }
            switch (choise)
            {
                 case 1 :
                    //Aufruf Methode Add
                    float endResult = Add(firstValue,secondValue); 
                    break;
                 case 2 :
                    //Aufruf Methode Substrah
                    break;
                 case 3 :
                    //Aufruf Methode Multiply
                    break;
                 case 4 :
                    //Aufruf Methode Divide
                    break;
                 default :
                    
                    break;
            }
    
    //catch { }

            
    }
}
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19341
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 27.01.10 11:02 
user profile iconvit30 hat folgendes geschrieben Zum zitierten Posting springen:
So sieht eingerückte Code aus.
Rufe ich Methode "Add" richtig auf?

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
        private int makeChoise(int choise)
        {
            Console.WriteLine("Für Addieren drücken Sie die 1","\r\n");
            Console.WriteLine("Für Substrahieren drücken Sie 2","\r\n");
            Console.WriteLine("Fur Multiplizieren drücken Sie 3","\r\n");
            Console.WriteLine("Für Dividieren drücken Sie 4","\r\n");
            //string Achoise = Console.ReadLine();
            int choiseline = int.Parse(Console.ReadLine());
            return choiseline;
               
        }
            switch (choise)
            {
Und dabei fällt dir nicht auf, dass das switch außerhalb deiner Methode makeChoise liegt oder wie?
vit30 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 38



BeitragVerfasst: Mi 27.01.10 11:24 
Zitat:
Und dabei fällt dir nicht auf, dass das switch außerhalb deiner Methode makeChoise liegt oder wie?


Schon aufgefallen. :shock:
Danke!

Moderiert von user profile iconChristian S.: Quote-Tag repariert