Area Calculator problems.

I am relatively new to programming. I started working on this calculator to calculate area. What I believe is the problem is the int length; line and the int width; line. I have a string in the program to show the area with the statement in the last line of code. I'm sorry in advance if it looks like I did all of this wrong.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  #include <iostream>
  #include <string>
  using namespace std;

    int main()
{
    int length;
    int width;
    cout << "Please enter the your length: ";
    cin >> length;
    cout << "Please enter your width: ";
    cin >> width;
    string area =
        length * width;
    cout << " The area of these values is :" << area << "\n";
}


Thanks,

Nikolai
Last edited on
Lines 13-14: You can't assign an int value (length * width) to a string.
Change line 13 to an int and you will be fine.

area does not need to be a string to use it in a cout statement.
Thank you so much. That helped a lot.
Also I guess I don't have the understanding of what a string is. Could you explain it to me?
std::string is a class that holds 0 or more characters.
http://www.cplusplus.com/reference/string/string/

Topic archived. No new replies allowed.