- Mesajlar
- 1,177
aşağıda yazdığım programı c#da metotlar öğrenmek için alıştırma yapıyordum... soru şu: 10 tane sayıyı metot kullanarak yapmak... bu soru başka bir sürü şekillerde yapılabilir ama öğrenmek açısından bu yöntemde inatlaştım.. böyle yaptığım zaman bana toplamı vereceği yerde "tane"yi veriyor yani 10u.. bunu da şöyle anladım taneye verdiğim değeri 10 değil de 5 yaptım bu sefer de ekrana 5 yazdırdı yani taneyi yazdırdı... c#a da yeni başladığım için tam emin değilim metotda böyle bi döngü olur mu diye... ekrana toplamı bi türlü yansıtamadım... kesinlikle yazım hatası yok... sadece bi yerde mantıksal bi hata var bulamadım... döngüyü yanlış da kurmuş olabilirim ama sağlamasını da yaptım ekrana toplamı vermesi gerekirken taneyi veriyor... sizce bu mantıksal hata nerde.. yardımcı olursanız sevinirim... :roll:
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 WindowsFormsApplication95
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int toplam=0;
public static int islem(int sayi)
{
int top =+sayi;
return top;
}
private void button1_Click(object sender, EventArgs e)
{
int tane = 10;
int s = 0;
for (int j = 0; j < tane; j++)
{
s = +1;
int sonuc = islem(s);
toplam =toplam+sonuc;
}
MessageBox.Show(toplam.ToString());
}
}
}
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 WindowsFormsApplication95
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int toplam=0;
public static int islem(int sayi)
{
int top =+sayi;
return top;
}
private void button1_Click(object sender, EventArgs e)
{
int tane = 10;
int s = 0;
for (int j = 0; j < tane; j++)
{
s = +1;
int sonuc = islem(s);
toplam =toplam+sonuc;
}
MessageBox.Show(toplam.ToString());
}
}
}