Here is the GPT-3 free online tool writing C# code as follows. The first part is my description of program...
《 etc 》
It does not create the form in code, and suppose, that is realistic, since this will be done by user.
And here is another problem; code normalization.
An experienced C# developer will be thinking classes, iterators, generics, event binding and anything else in the toolkit to make that forms code work in as few maintainable lines as possible. Not to mention the added/grinding complexity of Windows Presentation Foundation. Seeing this in production code might raise a few 'issues' in review.
My opinion is, regardless if language, the AI code generator is just a starting point for developers. Maybe this will become the finishing point go-to app for students programming in 'Arduino'? No one knows how or even why the code works, it just does.
I tried again, same request and the code was shortened considerably by utilizing "switch" instead of all of "else if" statements. The third time it even included remarks as I asked, code below:
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 Resistor_Color_Code_Decryption
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnDecode_Click(object sender, EventArgs e)
{
//define variables
string colorCode1, colorCode2, colorCode3, colorCode4;
int numValue1, numValue2;
double multiplier, tolerance;
//get user input
colorCode1 = txtColorCode1.Text;
colorCode2 = txtColorCode2.Text;
colorCode3 = txtColorCode3.Text;
colorCode4 = txtColorCode4.Text;
//calculate and display results
numValue1 = ColorCode(colorCode1);
numValue2 = ColorCode(colorCode2);
multiplier = Multiplier(colorCode3);
tolerance = Tolerance(colorCode4);
lblResult.Text = Result(numValue1, numValue2, multiplier, tolerance);
}
static int ColorCode(string colorCode)
{
int numValue = 0;
switch (colorCode.ToLower())
{
case "black":
numValue = 0;
break;
case "brown":
numValue = 1;
break;
case "red":
numValue = 2;
break;
case "orange":
numValue = 3;
break;
case "yellow":
numValue = 4;
break;
case "green":
numValue = 5;
break;
case "blue":
numValue = 6;
break;
case "violet":
numValue = 7;
break;
case "gray":
numValue = 8;
break;
case "white":
numValue = 9;
break;
default:
MessageBox.Show("Invalid Color Code");
break;
}
return numValue;
}
static double Multiplier(string colorCode)
{
double multiplier = 1;
switch (colorCode.ToLower())
{
case "black":
multiplier = 1;
break;
case "brown":
multiplier = 10;
break;
case "red":
multiplier = 100;
break;
case "orange":
multiplier = 1000;
break;
case "yellow":
multiplier = 10000;
break;
case "green":
multiplier = 100000;
break;
case "blue":
multiplier = 1000000;
break;
case "violet":
multiplier = 10000000;
break;
case "gray":
multiplier = 100000000;
break;
case "white":
multiplier = 1000000000;
break;
default:
MessageBox.Show("Invalid Color Code");
break;
}
return multiplier;
}
static double Tolerance(string colorCode)
{
double tolerance = 20;
switch (colorCode.ToLower())
{
case "brown":
tolerance = 1;
break;
case "red":
tolerance = 2;
break;
case "green":
tolerance = 0.5;
break;
case "blue":
tolerance = 0.25;
break;
case "violet":
tolerance = 0.1;
break;
case "gray":
tolerance = 0.05;
break;
case "gold":
tolerance = 5;
break;
case "silver":
tolerance = 10;
break;
default:
MessageBox.Show("Invalid Color Code");
break;
}
return tolerance;
}
static string Result(int numValue1, int numValue2, double multiplier, double tolerance)
{
double result = (numValue1 * 10 + numValue2) * multiplier;
string strResult = "";
strResult = result.ToString() + " ohms, +/- " + tolerance.ToString() + "%";
return strResult;
}
}
}
I don't think this machine learning tool will replace programmers at all, but it does give a quick starting point as you said. I don't consider myself a programmer and this work would have taken me 1.5 to 2 hours to complete, and then I may have rewritten again. I have written some user tools and over the last 30 years and some stuff specific to hardware that I have designed, but i never considered myself a coder (programmer). This would have saved me hours in my work so I can be working on other machine design issues.
Doesn't matter to me anymore, since I am retired.