problem with opertaions with numbers

im trying to find a way to add 2 numbers to gether . ANY way??

#include <iostream>
using namespace std;
int main ()
{
double num1;
double num2;
char op;

cout << "enter your miles per gallon ration" <<endl;
cin >> num1;
cout << "now how far? in miles" << endl;
cin >> num2;

//right here is whhere the problem is
return 0;
}
closed account (Lv0f92yv)
If you want to add two numbers, use the '+' operator between the varialbes (or constants) you want to add:

...
1
2
3
4
5
6
7
8
void main()
{
int a = 5;
int b = 10;
int result = a + b;
cout << result; //will output 15
...
}


Check out the documentation on this site, it is very useful.
Last edited on
FYI, that should be int main()
no the number has to be inputted then multiplied with another number its not a calculater either
closed account (Lv0f92yv)
Multiplying numbers is done the same way, using the * operator.

Get a number from the user (presumably from keyboard input, cin >>), store it in a variable of appropriate type (int, double etc), and multiply it using * with whatever other number/variable you want.

If this is not what you are trying to do, I apologize. Please clarify.
Topic archived. No new replies allowed.