Keep saying The variable 'width' is being used without being initialized.

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

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

    cout << "Enter The Length Of The Rectangle: "; 
    cin >> length; 
    area=length*width; 

    cout <<"The area of the rectangle is : "<< area << endl;

    return 0; 
}

Edited 4 Years Ago by deceptikon: Changed to a discussion thread

The error isn't unclear or ambiguous. width doesn't have a predictable value when you try to use it. You probably wanted another input request to fill it in just like length:

#include <iostream>
#include <cmath>

using namespace std; 

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

    cout << "Enter The Length Of The Rectangle: "; 
    cin >> length; 

    cout << "Enter The Width Of The Rectangle: "; 
    cin >> width; 

    area = length * width; 

    cout <<"The area of the rectangle is : "<< area << endl;

    return 0; 
}

Also try this:

#include <iostream>
#include <cmath>

using namespace std;

void continue_()
{
    char c;
    cout << "Press any key to end program: ";
    cin >> c; 
    cout << endl;
}

int main()
{
    float area, length, width;

    cout << "What is your length? ";
    cin >> length;
    cout << endl;

    cout << "What is your width? ";
    cin >> width;
    cout << endl;

    cout << "Area = Length * Width" << endl << endl;

    area = (length * width);

    cout << "Your Area is: " area << endl << endl;

    continue_();
    return 0;
}

The admin posts above everyone else's states that we shouldn't use system("pause"), but that we should make up our own. So practice that also.

This article has been dead for over six months. Start a new discussion instead.