Help with simple formula

I want to know how to make this simple formula work, whatever I do I always get 0 as if the formula is ignored. As seen below I want it so that if I type "area" it will automatically do the formula for me. I know that you can simply use
"cout << length*width << endl;"
but that's not what I'm trying to do here, I need to know how to make it automatically use a formula.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<iostream> // For cin, cout, and system
#include<string> // For string data type
#include<conio.h> // For getch function
#include<iomanip> // For fixed funciton
using namespace std; //So "std::cout" will be abbreviated to "cout"

int main()
{
	//Variables
	float length;
	float width;
	float area;

	area = length*width;

	//Asking for input
	cout << "Enter the length and width." << endl;
	cin >> length; 
	cin >> width;

	//Output
	cout << "Your area is: " << area << endl;

	return 0;
Last edited on
Move line 14 below line 19 - goes with the principle of declaring/defining variables where you need them
Thank you, I thought it was all declared in the beginning.
Topic archived. No new replies allowed.