Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > โปรแกรมในการคำนวณจำนวนธนบัตร/เหรียญ ที่ต้องจ่ายกรณีมีการรับค่า



 

โปรแกรมในการคำนวณจำนวนธนบัตร/เหรียญ ที่ต้องจ่ายกรณีมีการรับค่า

 



Topic : 052316



โพสกระทู้ ( 112 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook



เราอยากรู้ว่าถ้าจะเขียน โปรแกรมในการคำนวณจำนวนธนบัตร/เหรียญ ที่ต้องจ่ายกรณีมีการรับค่า
เงินเดือน
โดยมี ธนบัตร/เหรียญ 1000,500,100,50,20,10,5,2,1,0.50,0.25


คือตอนนี้เราทำได้แต่กำหนดเงินเดือนลงไปแล้วคำนวน

อยากอยู่ว่า จะใช้ Array เข้ามาช่วยยังไง

Code (VB.NET)
Module HW4_2
    Sub main()
        Dim salary As Double = 32767.75
        Dim B1000, B500, B100, B50, B20, T10, T5, T1, T2, T50, T25 As Integer

        B1000 = Int(salary / 1000)
        Console.WriteLine("Num. of Bank 1000 = " & B1000)
        salary = salary Mod 1000
        Console.WriteLine("Remain salary = " & salary)
        B500 = Int(salary / 500)
        Console.WriteLine("Num. of Bank 500 = " & B500)
        salary = salary Mod 500
        Console.WriteLine("Remain salary = " & salary)
        B100 = Int(salary / 100)
        Console.WriteLine("Num. of Bank 100 = " & B100)
        salary = salary Mod 100
        Console.WriteLine("Remain salary = " & salary)
        B50 = Int(salary / 50)
        Console.WriteLine("Num. of Bank 50 = " & B50)
        salary = salary Mod 50
        Console.WriteLine("Remain salary = " & salary)
        B20 = Int(salary / 20)
        Console.WriteLine("Num. of Bank 20 = " & B20)
        salary = salary Mod 20
        Console.WriteLine("Remain salary = " & salary)
        T10 = Int(salary / 10)
        Console.WriteLine("Num. of Bank 10 = " & T10)
        salary = salary Mod 10
        Console.WriteLine("Remain salary = " & salary)
        T5 = Int(salary / 5)
        Console.WriteLine("Num. of Bank 5 = " & T5)
        salary = salary Mod 5
        Console.WriteLine("Remain salary = " & salary)
        T2 = Int(salary / 2)
        Console.WriteLine("Num. of Bank 2 = " & T2)
        salary = salary Mod 2
        Console.WriteLine("Remain salary = " & salary)
        T1 = Int(salary / 1)
        Console.WriteLine("Num. of Bank 1 = " & T1)
        salary = salary Mod 1
        Console.WriteLine("Remain salary = " & salary)
        T50 = Int(salary / 0.5)
        Console.WriteLine("Num. of Bank 0.50 = " & T50)
        salary = salary Mod 0.5
        Console.WriteLine("Remain salary = " & salary)
        T25 = Int(salary / 0.25)
        Console.WriteLine("Num. of Bank 0.25 = " & T25)
        salary = salary Mod 0.25
        Console.WriteLine("Remain salary = " & salary)
    End Sub
End Module





Tag : .NET, VB.NET







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-11-27 01:04:14 By : badtzyui View : 6274 Reply : 8
 

 

No. 1



โพสกระทู้ ( 1,603 )
บทความ ( 1 )



สถานะออฟไลน์


Code (VB.NET)
Module HomeWork_4_2 

	Public Shared Function MoneyDistribution(ByVal argMoney As Double) As String 
		Dim retStr As String = String.Empty 
		Dim CountType() As Double = New Double() _
			{1000 ,500 ,100 ,50 ,20 ,10 ,5 ,2 ,1 ,.5 ,.25}
		Dim calcValue As Double = argMoney 
		
		For i As Integer = 0 to CountType.Length -1
			Dim totalUnit = System.Convert.ToInt32( calcValue / CountType(i))
			If( totalUnit > 0 ) Then
				calcValue = calcValue - ( totalUnit * CountType(i))  	
				Dim moneyType As String = If((CountType(i) > 10), "billie", "coin")
				retStr = string.Format( "{0}Num. of {1} {2} baht(s) = {3}" & vbCr _
					,retStr ,moneyType ,CountType(i).ToString("#,##0") ,totalUnit.ToString("#,##0")) 
			End If
		Next	
    
    Return retStr
		
	End Function

End Module 









ประวัติการแก้ไข
2010-11-27 07:31:04
2010-11-27 16:52:01
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-11-27 07:29:14 By : blurEyes
 


 

No. 2



โพสกระทู้ ( 112 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

error



มันERROR 2 จุดที่วงไว้อะค่ะ ช่วยดูหน่อย

เรียนใช้ Console เขียนนะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-11-27 15:37:50 By : badtzyui
 

 

No. 3



โพสกระทู้ ( 112 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

เราใช้ ConsoleApplication เขียนนะ ไม่ได้ใช้ windownApp
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-11-27 15:40:56 By : badtzyui
 


 

No. 4



โพสกระทู้ ( 1,603 )
บทความ ( 1 )



สถานะออฟไลน์


^^ เขียนถูกแล้วค่ะ คุนนั่นแหละที่ผิด
Code (VB.NET)
Sub Main

   Console.WriteLine( MoneyDistribution(24900.75) )

End Sub

Public Shared Function MoneyDistribution(ByVal  argMoney As Double) As String
....
....

ส่วนเราใช้ Notepad++ เขียนน่ะ


ประวัติการแก้ไข
2010-11-27 16:51:39
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-11-27 16:48:14 By : blurEyes
 


 

No. 5



โพสกระทู้ ( 112 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

โค้ดใช้ได้แล้ว แต่พอรันแล้ว โปรแกรมโชว์ แต่ว่าใช้แบงค์1000 กีใบ ส่วนอันอื่นไม่ได้บอก เหมือนว่าโปรแกรมไม่วนอ่ะค่ะ

เราลองแก้ดูแล้วก็ไม่ได้ คือ ต้องให้มันพอใส่ค่าเงินเดือน ลงไปแล้ว โปรแกรมต้องบอกว่าได้ ต้องใช่ แบงค์ 1000, 500, 100, 50, 20 และ เหรียญ 10 , 5 , 2 , 1 ,0.50 , 0.25 กี่เหรียญ

เช่น ถ้าเราใส่จำนวนเงินเดือน 37988.75 ก็จะมี

แบงค์ 1000 = 37 ใบ
แบงค์ 500 = 1
แบงค์ 100 = 4
แบงค์ 50 = 1
แบงค์ 20 = 1

เหรียญ 10 = 1

เหรียญ 5 = 1
เหรียญ 2 = 1
เหรียญ 1 = 1
เหรียญ 0.50= 1
เหรียญ 0.25 = 1


ประมาณนี้อ่าค่ะ



คือเราทำได้แต่แบบไม่ใช้ Array อ่าค่ะ


ช่วยหน่อยนะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-11-28 17:42:15 By : badtzyui
 


 

No. 7



โพสกระทู้ ( 1,603 )
บทความ ( 1 )



สถานะออฟไลน์


Code (VB.NET)
    Public Shared Function MoneyDistribution(ByVal argMoney As Double) As String
        Dim retStr As String = String.Empty
        Dim CountType As Double() = New Double() {1000, 500, 100, 50, 20, 10, _
         5, 2, 1, 0.5, 0.25}
        Dim calcValue As Double = argMoney
        Const cxSpace As Char = " "c
        Const cxNewLine As String = vbCrLf

        For i As Integer = 0 To CountType.Length - 1
            Dim totalUnit As Integer = 0
            Dim moneyFlag As Double = CountType(i)
            If moneyFlag <= calcValue Then
                totalUnit = Int(calcValue / moneyFlag)
            End If
            If (totalUnit > 0) Then
                calcValue = calcValue - (totalUnit * moneyFlag)
                Dim moneyType As String _
                    = String.Format("[{0}]", If((moneyFlag > 10), "billie", "coin").PadLeft(7, cxSpace))
                retStr = String.Format("{0}Num. of {1} {2} baht(s) = {3}" & cxNewLine _
                    , retStr, moneyType _
                    , moneyFlag.ToString("#,##0.00").PadLeft(8, cxSpace) _
                    , totalUnit.ToString("#,##0").PadLeft(10, cxSpace))
                If calcValue = 0 Then
                    Exit For
                End If
            End If
        Next

        Return retStr

    End Function

test แล้วค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-11-28 22:30:48 By : blurEyes
 


 

No. 8



โพสกระทู้ ( 112 )
บทความ ( 0 )



สถานะออฟไลน์
Facebook

ขอบคุณมากค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-11-29 01:25:27 By : badtzyui
 


 

No. 9

Guest


Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim m As Decimal
m = Val(TextBox1.Text)

If m >= 1000 Then
Label1.Text = "แบงค์พัน" & Math.Floor(m / 1000) & "ใบ"
m = m Mod 1000
End If

If m >= 500 Then
Label2.Text = "แบงค์ห้าร้อย" & Math.Floor(m / 500) & "ใบ"
m = m Mod 500
End If

If m >= 100 Then
Label3.Text = "แบงค์หนึ่งร้อย" & Math.Floor(m / 100) & "ใบ"
m = m Mod 100
End If

If m >= 50 Then
Label4.Text = "แบงค์พ้าสิบ" & Math.Floor(m / 50) & "ใบ"
m = m Mod 50
End If

If m >= 20 Then
Label5.Text = "แบงค์ยี่สิบ" & Math.Floor(m / 20) & "ใบ"
m = m Mod 20
End If

If m >= 10 Then
Label6.Text = "เหรียญสิบ" & Math.Floor(m / 10) & "เหรียญ"
m = m Mod 10
End If

If m >= 5 Then
Label7.Text = "เหรียญห้า" & Math.Floor(m / 5) & "เหรียญ"
m = m Mod 5
End If

If m >= 2 Then
Label8.Text = "เหรียญสอง" & Math.Floor(m / 2) & "เหรียญ"
m = m Mod 2
End If

If m >= 1 Then
Label9.Text = "เหรียญหนึ่ง" & Math.Floor(m) & "เหรียญ"
Label9.Visible = True
m = m Mod 1
End If

If m >= 0.5 Then
Label10.Text = "เหรียญยี่สิบห้าสตางค์" & Math.Floor(m / 0.5) & "เหรียญ"
m = m Mod 0.5
End If

If m >= 0.25 Then
Label11.Text = "เหรียญยี่สิบห้าสตางค์" & Math.Floor(m / 0.25) & "เหรียญ"
m = m Mod 0.25
End If

End Sub
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2019-10-02 14:43:17 By : อ.ทรัพย์
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : โปรแกรมในการคำนวณจำนวนธนบัตร/เหรียญ ที่ต้องจ่ายกรณีมีการรับค่า
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่