My Computer Forum Computer Science Forum

Go Back   My Computer Forum > Computer Science Forum > Programming

Programming Programming Languages, Interpreters, and Compilers - Assembly, Declarative, Machine, Object Oriented, Iterative


Reply
 
LinkBack Thread Tools Display Modes
June 4th, 2010, 06:26 AM   #1
 
Joined: May 2010
Posts: 2
Building a basic calculatror

I am trying to build a basic calculator . I wrote these codes but not sure where it goes wrong .

import java.util.Scanner;

class testing {
public static void main (String args[]){
Scanner calculator = new Scanner (System.in);
double fn , sn , tn , 4n ,ans ;
System.out.println ("Your first number: ");
fn = calculator.nextDouble();
System.out.println ("Your second number: ");
sn = calculator.nextDouble();
System.out.println ("Your third number: ");
tn = calculator.nextDouble();
System.out.println ("Your fourth number: ");
4n = calculator.nextDouble();
ans = fn + sn - tn * 4n ;
System.out.println (ans);

}

}
stuart is offline  
 

My Computer Forum is free to register and we welcome everyone!

June 9th, 2010, 09:49 PM   #2
 
Joined: May 2010
Posts: 23
Re: Building a basic calculatror

Don't know about java but here I've got this C code you can try, this will make a calculator, simple one, really simple one...

Code:
#include <stdio.h>
#include <conio.h>
void main()
{
int no1,no2,no3,geto;
clrscr();
printf("***************SIMPLE CALCULATOR***********************\n");
printf("\n\nDisplay your opening message on here");
printf("\n\nPress any key to continue...");
getch();
clrscr();
printf("\n\n\n________Menu-:");
printf("\n>>Press 1 to add two numbers>>");
printf("\n>>Press 2 to subtract two numbers>>");
printf("\n>>Press 3 to multiply two numbers");
printf("\n>>Press 4 to perform a perfect division>>");
printf("\n");
scanf("&geto");
clrscr();
printf("Enter the first no to calculate...");
scanf("&no1");
printf("\nEnter the second no to calculate...");
scanf("&no2");
printf("\n\nPress any key to see the results...");
getch();
clrscr();
if(geto==1)
{
no3=no1+no2;
}
else if(geto==2)
{
no3=no1-no2;
}
else if(geto==3)
{
no3=no1*no2;
}
else if(geto==4)
{
no3=(no1/no2)
}
printf("The results of your calculation are as following... %d", no3");
printf("\n\nPress any key to exit the application...");
getch();
}

As I told you that it is a really simple one, if you need any more help about this you can ask me about that, or if you want to make some advanced calculator.
chetanbhasin is offline  
Reply

  My Computer Forum > Computer Science Forum > Programming

Tags
basic, building, calculatror



Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
some basic question mhhjt Artificial Intelligence 0 November 1st, 2013 01:01 PM
Building a Computer with Quad Display ryanandrews33 OS Architecture 0 January 30th, 2013 02:40 PM
Building a forum frosty16 Web Design 4 September 16th, 2012 03:07 AM
Visual Basic 6 Question KingATG Programming 2 December 9th, 2011 01:43 AM
Visual Basic InvalidOperationException SidT Programming 1 July 19th, 2009 09:48 PM





Copyright © 2018 My Computer Forum Forum. All rights reserved.