Oh Man, Need Help Making Basic Calc In Console App

free web hosting
Free Web Hosting > Computers & Tech > Programming > Programming General > BASIC / Visual Basic (.NET)

Oh Man, Need Help Making Basic Calc In Console App

broli
I'm stressing out here >_< I'm like so new to vb and console applications. I'm trying to make a calculator in console applications that
can keep adding when i type numbers in until i type '-1' AFter that -1 it would:
give me the total number of entered(+1 each time a number is added),
total scores combined, and
an average of total scores/total numbers entered.

Sad thing is, I'm much better on GUI sleep.gif I made one in GUI so easily, I guess console is that different.
I can get the average, but the scores and total numbers won't go sometimes.

Reply

miCRoSCoPiC^eaRthLinG
QUOTE(broli @ Dec 11 2005, 05:12 AM)
I'm stressing out here >_<  I'm like so new to vb and console applications.  I'm trying to make a calculator in console applications that
can keep adding when i type numbers in until i type '-1' AFter that -1 it would:
give me the total number of entered(+1 each time a number is added),
total scores combined, and
an average of total scores/total numbers entered.

Sad thing is, I'm much better on GUI sleep.gif  I made one in GUI so easily, I guess console is that different.
I can get the average, but the scores and total numbers won't go sometimes.
*





It's fairly easy - am pasting the working code below. This employes the Console.ReadLine and Console.WriteLine methods to get input and print output respectively. However, ReadLine accepts a string only and I'm using CType to type cast it to an Integer. If you enter an Alphabetic character or a Punctuation mark in the input, this will cause the code to crash. If you want the input checking to be implemented at every step, that can be done too wink.gif So let me know..

CODE

Module ConsoleCalc

   Sub Main()

       'Variables
       Dim Num, TotalNums, Sum As Integer

       'Print out info and prompt
       Console.WriteLine("Enter a series of numbers below, one in each line.")
       Console.WriteLine("When you want to end, enter -1")

       'Init Vars
       TotalNums = 0
       Sum = 0

       'Loop till -1 is entered
       Do

           'Accept a number
           Num = CType(Console.ReadLine, Integer)

           'Check if number is not -1, then add to sum and increment turn
           'If you don't introduce this second check, even the -1 will be counted as a number
           'is the series and added to it - also the total numbers entered will be wrong
           'and throw the average off
           If Num <> -1 Then

               'Add to sum
               Sum += Num

               'Increment Turn
               TotalNums += 1

           End If

       Loop While Num <> -1

       'Print the results
       Console.WriteLine("Total numbers entered: " & TotalNums)
       Console.WriteLine("Sum of all numbers: " & Sum)
       Console.WriteLine("Average: " & Sum / TotalNums)

   End Sub

End Module



I wrote it off in 5 mins and tried it out - fully funtional. If you have any problems running it let me know immediately by return post.

 

 

 


Reply

broli
CODE
     
 'Print results
       Console.WriteLine("Total Numbers: " & TotalNumbers)
       Console.WriteLine("Sum of scores: " & Sum)
       Console.WriteLine("Average of scores: " & Sum / TotalNumbers)
       Console.WriteLine("")
       Console.WriteLine("Press return to continue...")
       Console.ReadLine()


Alright that really helped me out. Somehow when I tried to do that like &Sum/ TotalNumbers, I got build errors. What I didn't check was my Dim. I got Sum mixed with Add. Don't know why I called it Add so that messed me up. I didn't notice it because I think I was going crazy trying to figure out what things did like console.writeline and etc.

So I fixed it up, and checked all my other codes, and I was suprised mine was like yours, just excluding those minor build errors and less commenting on mine. I'm shy on commenting, but getting better. Also, on my code, I added a few extra lines as you can see. That way when -1 is entered, it'll freeze on the results.

I gotta say this. YOU HELPED ME BIG TIME !! Thanks so much M^E . I'm just beginning my first semister as a college student doing this, and console applications was just random to me. Feels like a GUI, but coding is slightly different, and enough to make me ask for help. So yeah, THANKS !!

Reply

miCRoSCoPiC^eaRthLinG
Awesome smile.gif Glad that helped.. Any problems about VB/C# feel free to ask. Also the build error u got might have risen out of the fact you did &Sum / TotalNumbers.

See VB is a language that doesn't need you to explicitly declare the variables before you start using them. So even if you used Dim to define Add on the top and then used Sum instead, in the code - no errors will be detected. However, I've noticed in VS.NET editor, sometimes, when you type a "&" symbol and a variable name together - it doesn't autoformat correctly and separate them out...

Your &Sum / TotalNums should get formatted instantly to & Sum / TotalNums.. but that doesn't always happen. If the & sticks to the variable name, it will surely produce build errors.

Reply

broli
Oh now that you mention it, that's right haha. Hm... Yeah usually the autocorrect does the small things for me too, just not this time... Another thing I better keep my guard up smile.gif

Reply

FeedBacker
Needed;

3 Textbox's
Names:
Txt1.Text
Txt2.Text
Txt3.Text
Command Button
Name it anything

COMMAND BUTTON SUB HERE OR W/E

Dim FirstNum As Integer
Dim Cond as String
Dim SecNum As Integer
Dim Answer As String
Dim Message As String
Message = "Your Result Is: "
FirstNum = txt1.Text
Cond = txt2.Text
SecNum = txt3.Text

If Cond = "+" Then
Answer = FirstNum + SecNum
MsgBox(Message + Answer)
EndIf

If Cond = "/" Then
Answer = FirstNum / SecNum
MsgBox(Message + Answer)
EndIf

So on? got the idea?

-Joe Edwards

Notice from Approved by BH:

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

Recent Queries:-
  1. sum and average of integers on c# console application - 348.69 hr back. (3)
  2. making calculations in visual basic - 452.88 hr back. (1)
  3. visual basic 2005 coding of calculator - 467.07 hr back. (1)
  4. calculator coding for visual basic - 471.52 hr back. (1)
Similar Topics

Keywords : man, making, basic, calc, console, app

  1. Making A Programming Language
    (6)
  2. Basic C++ Coding
    (9)
    Hi everyone today i am going to teach you a very simple program and how it is made. I wont get into
    anything fancy right now but will teach you how to run a program in the command prompt. ok first if
    you want any comments in you program code there are two ways to do this. first one i will show you
    is a block comment. /* This opens the comment you can have as many lines as you want in a block
    comment this is how you close a block comment */ Okay the second way is a line comment // A line
    comment can only be in that one line. CODE #include // this is to include t....
  3. Basic C Language, Functions
    (5)
    In a complicated and/or big C programs, a programmer might need to use the same peice of code more
    than one time. However repeating the code can be both time consuming and frustrating. Thats why we
    use functions. Definition: A function is a small subprogram having its own name and datatype. It
    is used to carry out certain operations more than one time without the need of repetition. One of
    the functions we all know is the main functions; void main(). I will explain the void later.
    Syntax: Each function is composed of 3 parts: Name of the function Info type of the....
  4. Help Making A Text Based Game.
    dont be alarmed by the topic name, come take a look. (7)
    Hi there, now ive read many posts on people asking for help on how to make a text based game,
    i'd like to make one myself and I know some PHP and MySQL to go for it. Ok that out of the way,
    the programming languages going to be used for it will be PHP and MySQL (if you've not already
    guessed that) I'm just looking for some help and stuff like that to get me on my way, im a
    complete beginner to this whole text based game stuff, sooo any help would be appreciated thanks!
    PS: dont say go to MCCodes or anything, that website is just a bunch of kiddies making s....
  5. Linux Partitioning Guide (new Users)
    A very basic guide to partitioning in linux designed for new users (1)
    QUOTE Partitioning Guide This guide is designed for users New to Linux. 1. All Linux users
    run as just that 'a user'. If you are moving from Windows it is most likely that you ran
    Windows as an 'Administrator' (root). In Linux, any task which alters the Operating System
    (OS) of a Linux distro requires 'root' privileges. You will need the 'root' password
    to do this. Basically, this gives you temporary access to the core of your OS. This is what makes
    Linux far more secure than Windows. 1. That being said you will now understan....
  6. Basic Html Tutorial
    Made it myself, hope you like it. (1)
    HTML stands for hyper text markup language. It is a basic coding language used on almost every
    website. There are some tags in HTML which must be used, whilst others are enhancing, but not
    essential. Below I shall list the essential tags and there uses: This tells the browser that
    the language between the tags is going to be HTML so it knows how to read it. Inbetween those tags
    come These tags tell the browser that all the content that you wish to be displayed is in there.
    They are the only essential tags for HTML! The list is short but if you only use them your ....
  7. Making Educational Game
    3d game, like walking in country (4)
    Please, i would like to make a progra/game like walking in a country, visiting houses. Specially
    church is in my mind. with some music(in church religious)..... or, but its not so important -
    meeting people and talking with them. I cant say, but something between RPG and adventure, maybe
    with some small missions like finding cross, or old pergamen.... but in 3D. Maybe i can download
    some 3d models from net, so 3d modeling is not required for this tool. Just engine - with physics,
    colisions detect, maybe water effect, but not so important, then i need no so many programmi....
  8. An Absolute Basic Guide To Algorithms For Dummies
    (0)
    I really want to learn about algorithms but i dont know how it works at all. Can anyone suggest a
    site, or more preferably a book that can introduce me to algorithms?....
  9. Making Xp Look Like Vista
    (3)
    QUOTE For those that are not planning to install Windows Vista anytime soon, and want the styles
    and feel Vista has to offer when it comes to eyecandy and functionality, there are a few ways you
    can do this which can change not only the skins to Vista, but also icons, menus and your bootup
    screens. The most popular aspect of Vista is its Aero - Transparency and 3D Flip. To get opaque
    windows on Windows XP, you can try out a various software packages. Forget WindowsBlinds, thats not
    a true enablement of the Vista experience, what you really need is the BricoPack Vis....
  10. Help With Making A Textbased Game
    Help With Making A Textbased Game (6)
    hey i really want to make a web text based game like www.hattrick.org i really want it and i have a
    host .... i want to know where i can find a tutorial for it or what programs i need to use and....
    plz help me thanks....
  11. Help On Calc Date Issues !
    (4)
    Hi, all I need going to write a small function that calc some interval from day to day and to
    display it base on their size. For example, if the value was 1 minute or over that it display as x
    min. or if it hours then display it as x hours and so on. Let's say from a day range that has
    been passed 600000 second, than I have to change it to some mins or hours or days and so on.... I
    just get start with use the number of seconds and divide it with 60 and converted to mins, and go on
    up to days. But don't know how to get the next steps on. Any suggest are appr....
  12. Basic Css
    (6)
    can someone help me learn CSS or give me a good link to learn it....
  13. Need Help Making My Ftp Work
    my ftp is not working (14)
    I get this message: Status: Resolving IP-Address for ftp.losangelesmagazine.net Status: Connecting
    to 68.178.232.100:21... Error: Connection timed out Error: Could not connect to server I have used
    this this ftp before so I know it works. Is there any help anyone can give me? I would really
    appreciate any help with this and anyother topic I posted as I just activated my account today and
    I'm trying to figure out what to do to make this work so I can upload wordpress. I used the
    server and users name that I saw on cpanel and the message above is what I got. Tha....
  14. Making Xp Starts 60% Faster
    Making your windows xp starts faster and avoid hang ups. (3)
    By the way this is not my post I have found it in my pc and I forgot the source of it. I'll just
    share it here.
    ----------------------------------------------------------------------------------------------------
    ------------------------- QUOTE Making Windows XP Start 60% Faster Stopping Unneeded Startup
    Services Along with the core operating system and programs that Windows XP runs when it starts,
    there is also a host of services involved. Many of these services are necessary for Windows XP to
    operate correctly. However, many of them are for features in Wind....
  15. [php] Making Feeds Rss
    (3)
    Making feeds RSS with PHP I'm sorry if someone had already posted about it, but I have made
    some searches and did not find anything simmilar. RSS, very used nowadays by most of sites and it
    is one of the innovations that came with the famous Web2.0 For who doesn't know, RSS is a
    subset of dialects XML that are use to join content or Web syndication could be acceded by
    programmes/websites packers. It is used mainly in sites of news and blogs. The abbreviation of RSS
    is used to refer to the following patterns: - Rich Site Summary (RSS 0.91) - RDF Site Summ....
  16. Html Basic Tutorial
    <!-- For beginners only --> (9)
    Knowledge HTML stands for H yper T ext M arkup L anguage. You cannot create an HTML file
    using a rich-text editor, such as Microsoft Word or Wordpad. HTML To write a basic HTML, you will
    need to start with this: CODE The html > tag tells the browser that this is an HTML page.
    To close any tag, the same tag will be repeted but with the "/" sign. For example, CODE   
         Page title    Did you notice the /title >, /head > & /html > tags? That's how we
    close the tag. The HEAD > Tag A head > tag will include the meta >, titl....
  17. Php Tutorial: Making A Shoutbox
    Requirements: PHP, MySQL (12)
    Hi everyone, I'm going to tell you how to make a simple shoutbox using PHP and MySQL. To start
    off, open up mysql in the command line, or phpmyadmin, and create a database called shoutbox. Next,
    enter the following sql into the command line, or the phpmyadmin sql box, while using the shoutbox
    database: CODE create table messages(author varchar(30), message text, time timestamp, mid int
    auto_increment, primary key(mid)); This creates the table we need to store the messages, note the
    "mid" column, this gives each message a seperate id number, we'll see why ....
  18. Making A Turn Based Game Like Ogame
    Help would be nice =D (9)
    The Idea came to me and Just wanted to know what kind of code I'll need to know ect ect Also
    Help would be nice, because I'm kind of fresh =D x....
  19. Phpbb - Installation Tutorial ( For Newbies Based On Astahost Cpane)l
    phpBB 2.0.22 installation Tutorial with basic steps. (5)
    Introduction!! Providing a comprehensive 'How To' tutorial guide, on the
    installation of phpbb 2.0.22 forum on your Astahost/cPanel account. Tutorial includes Downloading
    of files Uploading using cPanel File Manager CHMOD using cPanel File Manager MySQL database
    creation PhpBB initial configuration This guid will help everyone from beginners, with images and
    an in depth guide of what to do. Step 1 To start with we need to download PhpBB ( latest stable
    version is PhpBB 2.0.22 ). This can be done by visiting the PhpBB Downloads page which shou....
  20. C++: Basic Classes
    classes, objects, access labels, members, inline functions (5)
    This tutorial assumes that you have a basic knowledge of C++. You know how to use built-in types,
    like ints, doubles, chars, etc. You should know some types that are part of the STL, like vector,
    etc. Those types that come in the STL are just C++; you can create your own types just like those!
    Non built-in types are referred to as classes . To create a class, you just use the keyword class
    , the name of the class, and curly brackets. CODE //A class named MyClass class MyClass { };
    In fact, that is all we need to create variables, pointers, or references to t....
  21. Programming In Glut (lesson 4)
    Making 3D objects (7)
    Hello, in this tutorial we will be creating a 3D pyramid. We are building this tutorial from Lesson
    3, but I took out the 2D objects and placed a 3D pyramid in there instead. The 3rd axis for drawing
    can be a litle confusing, but after you get the hand of it you'll do fine. Now when you are
    setting a 3D vertex just remember that the camera is on the positive end of the z axis. So things
    that have a more positive z axis value are closer than verteces with a more negative value. Well
    let's get started We always start by including the glut library CODE #i....
  22. Lesson #1 - Introduction To C#
    Console Application (1)
    This tutorial will help get you started with C# Sharp. These tutorials will assume that you are
    using the Visual Studio environment. If you are just curious to test out some code, then you can
    copy and paste this code into your CS file, however, before doing so, make sure to name your project
    the same as the namespace on the code. But since this first program is fairly easy, it will not
    hurt to type it out. It is fairly easy and short. Also, this program is highly commented so it
    should be easy to follow along. Comments will have 2 forward slashes before them '....
  23. Visual Basic.NET Help Needed.
    (8)
    I have a project to submit this wednesday, and i have to make it a working program. Not a big one ..
    but just sumthing small that includes : Splitter, Progress Bar & Track Bar. I thought of making
    sumthing like the picture below, I would enter the text and hit the button .. the text would come in
    BOTH the labels. Then i move the track bar on the left to increase the font or/and the track bar on
    the right to change the color ( RBG only 3 colors ). The progress bar at the bottom will show the
    progress every time i move either of the track bars to a level. Nothing fanc....
  24. Turn Your Gaming Console Into A Media Center Pc
    (3)
    I was going to post this in the Gaming Boards, but I really think this has more to do with Computer
    Talk than Gaming. Recently my one friend, "hacked" his XBOX to allow it to become a Media Center
    computer. Through an exploit from Mech Assault for XBOX, he can run executable code from a Memory
    Card. Home brew developers created a easy to follow walkthrough to load OS-like software to the
    XBOX that turns it into a real easy to navigate Media Center. We can stream video, music, and
    photos from the computers on our LAN and download from the internet. I haven't seen....
  25. Making A Nice Looking Signature In Photoshop Cs
    Some basic Photoshop skills required... (17)
    Here's a guide you can use to help you make a signature image in Photoshop CS. Before we begin
    you need to pick out a good "render" for your signature. A render is basically an image that takes
    the focus in your signature, the render I will use currently looks like this First off I hit
    Ctrl+A and then Ctrl+C, then I go to File> New, and I set my image proportions to 410 wide, and 165
    high. Then I hit Ctrl+V and right click the eraser tool I select the Magic eraser tool, I hold down
    Ctrl and then left click my render. I move my render all the way to the right, th....
  26. Flash Site Software
    Help need for nice flash making software (14)
    Hello iam a newbie in flash ,And i want to make a Website Using flash, Can someone show me some easy
    to understand flash making software,I have macromedia flash mx but i dont understand a word in
    that..! its very complicated..! As i need an easy to use software..! /sad.gif' border='0'
    style='vertical-align:middle' alt='sad.gif' /> ....
  27. (Nearly) Ultimate Music Posting Guide
    Making your music available online (11)
    The (Nearly) Ultimate Music Posting Guide For several years, indie and established musicians
    relied on MP3.com as their primary off-site music host. While there were a small number of other
    similar sites, and MP3.com had its share of problems, it was still THE place to get your music
    posted. It also allowed artists and music fans to create "Stations" where customized playlists could
    be created and shared with the world. Vivendi Universal eventually bought MP3.com and ultimately
    shut it down only to rebuild it as a site for "established" artists, leaving all of the in....
  28. Visual Basic Help
    need help useing visual basic (7)
    i was just wondering, when you are useing the program Visual Basic is there any way to add some
    animation to a form, and if so what is a good(cheep) animation program i could get?....
  29. Pc Vs Console
    Which 1 Is better. pc or console ! (15)
    --------------------Pc --------- 1)Pc's cost more.But you get what you pay for. 2)Better
    graphics than console,Powerfuller and can do other things other than games.
    ----------------Console----------------------- 1)Made for gaming 2)cheaper 3)releases come out
    first(eg.gta:san andreas) ---------------conclusion---------- The pc is more versatile,and has
    more games.Pc is the better option GENERALLY. What do u Think ???....
  30. Basic Tutorial: PHP GD
    basic tuts (16)
    With php gd is the image function library of php. The functions include in this library enable php
    users to creating image up to manipulating photos. PHP gd can create with file extension of jpg,
    gif, swf, tiff and jpeg2000. Installation see http://www.php.net/manual/en/ref.image.php .
    Astahost hosting service has enable gd library, so won’t need any extra works except in coding.
    Lets get started, creating images from php set the canvas: CODE   $img = imagecreate(250, 80)
    imagecreate this function create and set a blank canvas with the wide of 250 pixels a....

    1. Looking for man, making, basic, calc, console, app






*SIMILAR VIDEOS*
Searching Video's for man, making, basic, calc, console, app
Similar
Making A Programming Language
Basic C++ Coding
Basic C Language, Functions
Help Making A Text Based Game. - dont be alarmed by the topic name, come take a look.
Linux Partitioning Guide (new Users) - A very basic guide to partitioning in linux designed for new users
Basic Html Tutorial - Made it myself, hope you like it.
Making Educational Game - 3d game, like walking in country
An Absolute Basic Guide To Algorithms For Dummies
Making Xp Look Like Vista
Help With Making A Textbased Game - Help With Making A Textbased Game
Help On Calc Date Issues !
Basic Css
Need Help Making My Ftp Work - my ftp is not working
Making Xp Starts 60% Faster - Making your windows xp starts faster and avoid hang ups.
[php] Making Feeds Rss
Html Basic Tutorial - <!-- For beginners only -->
Php Tutorial: Making A Shoutbox - Requirements: PHP, MySQL
Making A Turn Based Game Like Ogame - Help would be nice =D
Phpbb - Installation Tutorial ( For Newbies Based On Astahost Cpane)l - phpBB 2.0.22 installation Tutorial with basic steps.
C++: Basic Classes - classes, objects, access labels, members, inline functions
Programming In Glut (lesson 4) - Making 3D objects
Lesson #1 - Introduction To C# - Console Application
Visual Basic.NET Help Needed.
Turn Your Gaming Console Into A Media Center Pc
Making A Nice Looking Signature In Photoshop Cs - Some basic Photoshop skills required...
Flash Site Software - Help need for nice flash making software
(Nearly) Ultimate Music Posting Guide - Making your music available online
Visual Basic Help - need help useing visual basic
Pc Vs Console - Which 1 Is better. pc or console !
Basic Tutorial: PHP GD - basic tuts
advertisement




Oh Man, Need Help Making Basic Calc In Console App