VBScript Problem

Permabanned
Joined
21 Nov 2010
Posts
2,315
Location
Newton Aycliffe
Ok so im having some problems trying to get my code working at current, im restricted in what i can use so i have to stick to the outline in this code (No arrays).

Its a script that accepts numbers till a negative number is input but im struggling getting the values input from the user, in a string format to an integer, because i need to sum and average them later.

This is what im working off right now.

Option Explicit

dim userinput,overall, numberofnumbers

Do

WScript.StdOut.Write "Input a number: "
userinput = WScript.StdIn.ReadLine

overall = overall + userinput

numberofnumbers = numberofnumbers + 1

loop until (userinput < 0)

overall = CInt(overall)

WScript.StdOut.Writeline "Amount of numbers entered: " & numberofnumbers

WScript.StdOut.Writeline "Sum of numbers entered: " & overall
WScript.StdOut.Writeline "Average of numbers: " & (overall/numberofnumbers)

If anyone can think of a better way let me know, but as i said im restricted to certain variables and commands currently.
 
Last edited:
Thats exactly how i planned to do it, but its throwing up mismatch errors when inputting the negative number. Does the above work for you?

Sadly it must be VBS

Edit: nevermind youve done it with inputbox and i was trying to run in console, will report back in a sec :P
 
Yep your correct works perfectly, some reason i thought i needed to display the numbers entered back, when infact i didnt, and thus got the fact i needed to use a string when i did not in my head!

Thanks.
 
Back
Top Bottom