Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27173

VS 2012 Got Math?

$
0
0
I thought I nailed this one - but, I was wrong. I'm totally stumped - probably because it's 3am. I'm writing a console application to calculate the most cost efficient method of buying paper. It's not often someone needs and exact odd number of sheets of paper in the thousands, but for the sake of this application, they do. ;)

I'm coding accordingly to this rubric:

Name:  untitled.JPG
Views: 109
Size:  62.3 KB


Somewhere in this code is a mathematical error. I'm getting outputs just not correct ones.

Code:

    Sub Main()
        Dim sheets As Double
        Dim num1000 As Double
        Dim num500 As Double
        Dim num100 As Double
        Dim num As Double
        Dim cost1000 As Decimal
        Dim cost500 As Decimal
        Dim cost100 As Decimal
        Dim cost As Decimal
        Dim total As Decimal


        'INPUT
        Console.Write("Enter number of sheets of paper needed: ")
        Double.TryParse(Console.ReadLine, sheets)


        'PROCESSING
        num1000 = Math.Floor(sheets / 1000)
        num500 = sheets Mod 1000 / 500
        num100 = sheets Mod 500 / 100
        num = sheets Mod 100


        'OUTPUT
        If sheets Mod 1000 >= 645 Then num1000 = num1000 + 1 And num500 = num500 - 1 And num100 = num100 - 1 And num = num - 1
        Console.WriteLine("Number of 1000 packages: " & Int(num1000))

        If sheets Mod 500 >= 335 Then num500 = num500 + 1 And num100 = num100 - 1 And num = num - 1
        Console.WriteLine("Number of 500 packages: " & Int(num500))

        If sheets Mod 100 >= 55 Then num100 = num100 + 1 And num = 0
        Console.WriteLine("Number of 100 packages: " & num100)

        Console.WriteLine("Number of singles: " & num)

        cost1000 = Int(num1000) * 30
        cost500 = (Int(num500) * 20)
        cost100 = (Int(num100) * 5.5)
        cost = num * 0.1
        total = cost + cost100 + cost500 + cost1000

        Console.WriteLine("Total cost: $" & total.ToString("n2"))
        Console.ReadLine()
    End Sub

Kill the time away. Help a brother out. Zzz...
Attached Images
 

Viewing all articles
Browse latest Browse all 27173

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>