對不起,如果這可能不是以最好的方式解釋,但我基本上想要做的是顯示我創建的計算的輸出。這個計算是古埃及乘法(我給了一個故事來創建一個程序,用戶可以選擇使用這種方法計算值,並注意我們沒有大聲使用*和/運算符),我希望能夠顯示正在使用的權力,價值計算和整體結果。如果可能的話,我想把所有這些輸出都返回到彈出框中,但我不確定我將如何看待它,因爲我是C#(學徒)的新手。顯示計算過程的輸出
這裏是我多麼希望輸出
Powers: 1 + 4 + 8 = 13
Values: (1 * 238) + (4 * 238) + (8 * 238)
Result: 238 + 952 + 1904 = 3094
以下是我在一分鐘爲古egyption乘法的代碼示例: 注iReturnP =電源,iReturnN =值,iReturn =結果
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SimpleMath
{
public class AEM : IOperation
{
public int Calculate(int i, int j)
{
int[] ints = new int[] { i, j };
Array.Sort(ints);
List<int> powers = new List<int>();
int power = 1;
int first = ints[0];
int iReturn = 0;
int iReturnP = 0;
int iReturnN = 0;
do
{
powers.Add(power);
power = new Multiply().Calculate(power, 2);
} while (power <= first);
iReturnP += first;
while (first > 0)
{
int next = powers.LastOrDefault(x => x <= first);
first -= next;
int powertotal = new Multiply().Calculate(next, i);
iReturnN += next;
iReturn += powertotal;
}
return iReturnP;
return iReturnN;
return iReturn;
}
}
}
你不能返回的3倍!除了你真正的問題是什麼? – makc 2013-04-11 11:11:30
這是他的問題... – 2013-04-11 11:12:28
@makc初學程序員,削減一些懈怠 – LukeHennerley 2013-04-12 07:39:11