Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

# calculator

### #1 lilhawk2892 Posted 17 August 2005 - 12:04 PM

lilhawk2892

Member

• Member
• 128 posts
ok after looking i have a hard time reading this so here is an updated version

Im making a calculator.I think the formula is easy,x+y = answer.But im having a problem.How do i make the value of x the first number the user put in,and the value of y the second number the user put in. so can anybody help me

Edited by lilhawk2892, 17 August 2005 - 01:07 PM.

• 0

### #2 bdlt Posted 17 August 2005 - 04:33 PM

bdlt

Member

• Member
• 875 posts
you need a cin for x and a cin for y.

you will need a switch statement - so go back to the tutorials for switch().

when you are done you will have

double add( double x, double y ) { ... }
double sub( double x, double y ) { ... }
double mult( double x, double y ) { ... }
double div( double x, double y ) { ... }

don't forget to check for dividing by zero.

remember - when all else fails, google on calculator c++ !!!!!!!!!
• 0

### #3 lilhawk2892 Posted 17 August 2005 - 07:37 PM

lilhawk2892

Member

• Topic Starter
• Member
• 128 posts
thanks and looks like im nowhere near making a calculator i havnt gotten close to swith statements yet
• 0

### #4 chickenman Posted 18 August 2005 - 02:51 AM

chickenman

Member

• Member
• 37 posts
@bdlt
Who do you have to make things sound so hard

@lilhawk2892
here is a simple calculator to add two numbers

```#include <iostream>
using namespace std;

int main()
{
double a;
double b;
double total;
cout<<"Enter first number" << endl;
cin >> a;
cin.ignore();

cout<<"Enter second number" << endl
cin >> b;
cin.ignore();

total = a + b;
cout<<"The total of " a  " + "  b "  is  " total << endl;
cin.get();
return 0;
}
```

• 0

### #5 lilhawk2892 Posted 18 August 2005 - 01:26 PM

lilhawk2892

Member

• Topic Starter
• Member
• 128 posts
18 C:\Dev-Cpp\main.cpp expected `;' before string constant

can u pls fix it i really dont know where to put it
• 0

### #6 bdlt Posted 18 August 2005 - 01:43 PM

bdlt

Member

• Member
• 875 posts
the compiler found a problem with line 18.

18 C:\Dev-Cpp\main.cpp expected `;' before string constant

look carefully at line 18

`cout<<"Enter second number" << endl`

do you see anything missing?
• 0

### Similar Topics

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users