I've been working on this for hours I know the errors are staring me in the face but I just can't see them. Any help would be greatly appreciated.

//prb01-1.cpp
//This program calculates the total surface area of a pool

#include <iostream.h>
#include<iomanip.h>

//using namespace std:

int main()
{
    const int PRICE_SQ = 3.00;

    int depth,
        length,
        width,
        total;

//obtain input data
cout<<"\nEnter the length in feet";
cin>>length;
cout<<"\nEnter width";
cin>>width;
cout<<"\nEnter depth";
cin>>depth;

//Do the calculations
surface=2*depth*(length+width)+length*width;

//Display the results
cout << "\n length;"
cout << "\n width;"
cout << "\n depth;"
cout << "\n total surface area;"

return 0;
}

Error:

 warning C4244: 'initializing' : conversion from 'const double' to 'const int', possible loss of data
 error C2065: 'surface' : undeclared identifier
 error C2146: syntax error : missing ';' before identifier 'cout'
 error C2146: syntax error : missing ';' before identifier 'cout'
 error C2146: syntax error : missing ';' before identifier 'cout'
 error C2143: syntax error : missing ';' before 'return'
Error executing cl.exe.


 5 error(s), 1 warning(s)

Recommended Answers

All 5 Replies

First, your surface equation is wrong. Surface area is simply lengh*width. I'm not even sure what that equation you are using will actually calculate.

The warning comes from cramming a double into an int. Generally you would want to avoid that but in this case you can trust the compiler to do it properly. To remove the error though simply change the int into a double like so....

const double PRICE_SQ = 3.00;

The errors come from three areas. First

//using namespace std: -> using namespace std;

The next problem is that you did not declare your 'surface' variable. The final problem is with all your couts. All your semicolons are inside the ""s when it should be

cout << "\n length;" -> cout << "\n lengh";

well..here u have made some syntax errors....
your code

cout << "\n length;"//this must be semicolon (;) after double quotes
cout << "\n width;"//same here
cout << "\n depth;"//same here
cout << "\n total surface area;"//same here

correction

and once u have calculated , you need to display it...
the above code thus can be corrected to....

cout<<"\n length "<<length;
cout<<"\n width "<<width;
cout<<"\n depth "<<depth;
cout<<"\n total surface area "<<surface;


in the beginning...

you have declared as...

const int PRICE_SQ=3.00

but this is a float or a double value...and u are not using this anywhere in your code.

I hope this would do...

One quick thing i saw was when you did
cout << "\n length;"
cout << "\n width;"
cout << "\n depth;"
cout << "\n total surface area;"
you put the ; behind the " its sposed to look like this
cout << "\n length";
cout << "\n width";
cout << "\n depth";
cout << "\n total surface area";

This will get close, looked it over in the morning ...

// This program calculates the total surface area of a pool wall 
// and estimated construction cost    Dev-Cpp

#include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char *argv[])
{
  int depth,length,width,total;
  int surface;
  const double PRICE_SQ = 3.00;


  //obtain input data
  cout<<"\nEnter the length in feet ";
  cin>>length;
  cout<<"\nEnter width ";
  cin>>width;
  cout<<"\nEnter depth ";
  cin>>depth;

  //Do the calculations sides + bottom
  surface = 2*depth*(length + width) + length*width;

  //Display the results
  cout << "\n length             = " << length;
  cout << "\n width              = " << width;
  cout << "\n depth              = " << depth;
  cout << "\n total surface area = " << surface;
  cout << "\n cost               = " << surface * PRICE_SQ << endl;
  
  cin.get(); // wait
  return 0;
}

Also, it can be more exactly if you declare surface as double...

Sorry, no need to...I was sleeping, I guess...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.