Advertisement
DrAungWinHtut

Maths Quiz final

Feb 28th, 2022
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace _2022022401_CS_Login_Exam_2
  12. {
  13.     public partial class frmMaths : Form
  14.     {
  15.  
  16.         // external variables တွေ ကြေငြာမယ်။ ဘယ်နေရာကမဆို ခေါ်သုံးချင်လို့
  17.         int iTimes = 0;
  18.         int iCount = 0;
  19.         int iResult = 0;
  20.         int iTotal = 0;
  21.  
  22.         public frmMaths()
  23.         {
  24.             InitializeComponent();
  25.         }
  26.  
  27.         private void frmMaths_Load(object sender, EventArgs e)
  28.         {
  29.             txtTimes .Enabled = false;
  30.             txtCount .Enabled = false;
  31.             txtTotal  .Enabled = false;
  32.  
  33.             randomTest();
  34.  
  35.             txtTotal .Text  = iTotal .ToString ();
  36.  
  37.  
  38.         }
  39.  
  40.         private void btnCalculate_Click(object sender, EventArgs e)
  41.         {
  42.             int iAns = int.Parse(txtResult.Text); //tryParse
  43.             if (iAns == iResult)
  44.             {
  45.                 MessageBox.Show("Correct!");
  46.                 iTotal = iTotal + 10;
  47.                 txtTotal.Text = iTotal.ToString ();
  48.  
  49.                 randomTest();
  50.             }
  51.             else
  52.             {
  53.                 MessageBox.Show("Wrong Answer!");
  54.             }
  55.         }
  56.  
  57.         private void randomTest()
  58.         {
  59.             Random rnd = new Random();
  60.             iTimes = rnd.Next(1, 17);
  61.             iCount = rnd.Next(1, 13);
  62.             iResult = iTimes * iCount;
  63.  
  64.             txtTimes.Text = iTimes.ToString();
  65.             txtCount.Text = iCount.ToString();
  66.             txtResult.Clear();
  67.         }
  68.  
  69.         private void btnToMiles_Click(object sender, EventArgs e)
  70.         {
  71.             //float fKm = float.Parse(txtKm1 .Text );
  72.             bool bInput = float.TryParse(txtKm1.Text, out float fKm);
  73.             if (bInput)
  74.             {
  75.                 float fMiles = fKm * 0.62f;
  76.                 txtMiles1 .Text = fMiles .ToString ();
  77.             }
  78.             else
  79.             {
  80.                 MessageBox.Show("Error! Please Enter Correct Values for Km!");
  81.                 txtKm1.Focus();
  82.                 txtKm1 .SelectAll ();
  83.             }
  84.          
  85.         }
  86.  
  87.         private void btnToKm_Click(object sender, EventArgs e)
  88.         {
  89.             //float fKm = float.Parse(txtKm1 .Text );
  90.             bool bInput = float.TryParse(txtMiles2.Text, out float fMiles2);
  91.             if (bInput)
  92.             {
  93.                 float fKm2 = fMiles2  * 1.6f;
  94.                 txtKm2.Text = fKm2 .ToString();
  95.             }
  96.             else
  97.             {
  98.                 MessageBox.Show("Error! Please Enter Correct Values for Miles!");
  99.                 txtMiles2.Focus();
  100.                 txtMiles2.SelectAll();
  101.             }
  102.         }
  103.  
  104.         private void label10_Click(object sender, EventArgs e)
  105.         {
  106.  
  107.         }
  108.  
  109.         private void textBox4_TextChanged(object sender, EventArgs e)
  110.         {
  111.  
  112.         }
  113.  
  114.         private void label12_Click(object sender, EventArgs e)
  115.         {
  116.  
  117.         }
  118.  
  119.         private void textBox3_TextChanged(object sender, EventArgs e)
  120.         {
  121.  
  122.         }
  123.  
  124.         private void label11_Click(object sender, EventArgs e)
  125.         {
  126.  
  127.         }
  128.  
  129.         private void textBox2_TextChanged(object sender, EventArgs e)
  130.         {
  131.  
  132.         }
  133.  
  134.         private void label13_Click(object sender, EventArgs e)
  135.         {
  136.  
  137.         }
  138.  
  139.         private void btnCalculateGP_Click(object sender, EventArgs e)
  140.         {
  141.             float fGPPK = 0.0f;
  142.             float fKyat = 0.0f;
  143.             float fPae = 0.0f;
  144.             float fYway = 0.0f;
  145.  
  146.             bool bGPPK = float.TryParse (txtGppk .Text , out fGPPK);
  147.             bool bKyat = float.TryParse (txtKyat .Text , out fKyat);
  148.             bool bPae = float.TryParse (txtPae .Text , out fPae);
  149.             bool bYway = float.TryParse (txtYway .Text , out fYway);
  150.  
  151.             // if( (bGPPK == true) && (bKyat == true) && (bPae == true) && (bYway == true) )
  152.             if (bGPPK && bKyat && bPae && bYway )
  153.             {
  154.                 float fTotalGW = fKyat +(fPae / 16) + (fYway / 128);
  155.                 float fTotalGP = fTotalGW * fGPPK;
  156.                 txtGoldPrice.Text = fTotalGP.ToString();
  157.             }
  158.             else
  159.             {
  160.                 MessageBox.Show("Wrong Inputs, Pls Try Again");
  161.                 txtGppk.Clear();
  162.                 txtKyat .Clear ();
  163.                 txtPae .Clear ();
  164.                 txtYway .Clear ();
  165.                 txtGppk.Focus();
  166.             }
  167.  
  168.         }
  169.     }
  170. }
  171.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement