# first program: how many bricks do i need calculator

Printable View

• 05-31-2012
Ben Atkins
first program: how many bricks do i need calculator
hi everyone, I have just created my first program in visual c++ 2008 and after many frustrating hours to make a calculator to find out how many bricks id need in a wall. Also to find a cost.

Any ways of improving my program will be greatly appreciated. Hope it doesn't turn out ugly.

Here it is:

Code:

``` // How many bricks in a wall calc #include <iostream> using namespace std; int main() {   int length, courses, totalbricks, totalprice;   cout << "Ayup duck, iv heard you are planning to build a brick wall,";   cout << endl << "and it just so ";       cout << "happens that im a quantity surveyor!" << endl << endl;   cout << "How long in meter(s) do you want this wall to be then luv??: ";   cin >> length;   cout << endl;   cout << "Yes, yes, ok your wall will be " << length << " metre's long." << endl << endl;   cout << "how many course of bricks high do you want your wall to be? ";   cin >> courses;   cout << endl;   cout << "ok your wall will have " << courses << " courses." << endl << endl;  totalbricks = 10*(length*courses);  totalprice = 6*totalbricks;     cout << "you will need about " << totalbricks << " bricks!" << endl << endl;   cout << "( I am assuming that you are using my special 10cm long bricks that";     cout <<  " you can glue together so no gap";         cout <<"or need for mortar! only \$6 EACH special offer!)" << endl << endl;   cout << "It will only cost you \$" << totalprice;   cout << ", so your looking at a real bargain!" << endl << endl;       cout << "Now be a darlin' will ya and put the kettle on... cheers" << endl << endl;     return 0;     }```
• 05-31-2012
Salem
Adjacent cout statements can be combined.
Code:

```  cout << "Ayup duck, iv heard you are planning to build a brick wall,"     << endl << "and it just so "     << "happens that im a quantity surveyor!" << endl << endl     << "How long in meter(s) do you want this wall to be then luv??: ";```
• 05-31-2012
Ben Atkins
I tried to add a command like:

Code:

```if totalprice -= 1500 cout << "don't waste my time";```
I want to make maybe a text based game or story with choices for my next effort. Sorry my post was so short above. I wrote it out better but it got wiped when i tried posting as it logged me out from facebook without me noticing.
• 05-31-2012
Ben Atkins
thanks Salem. that makes sense to me. Im really over cautious still trying not to get errors hehe
• 05-31-2012
Neo1
Quote:

Originally Posted by Ben Atkins
thanks Salem. that makes sense to me. Im really over cautious still trying not to get errors hehe

Don't be afraid of errors, errors are your friend!

You will never learn unless you try out new stuff, if the compiler gives you an error, you've now learnt something :-)
• 05-31-2012
Elkvis
Quote:

Originally Posted by Ben Atkins
I tried to add a command like:

Code:

```if totalprice -= 1500 cout << "don't waste my time";```

the condition of your if statement needs to be in parentheses, and I don't think you'll get the results you expect from (totalprice -= 1500). that will return true any time totalprice is not equal to 1500.
• 05-31-2012
Ben Atkins
Hey thanks thats fixed it! Now i can see what else i can get my teeth into thanks :)
• 06-02-2012
samwillc
Quote:

Originally Posted by Ben Atkins
Code:

``` // How many bricks in a wall calc #include <iostream> using namespace std; int main() {   int length, courses, totalbricks, totalprice;   cout << "Ayup duck, iv heard you are planning to build a brick wall,";   cout << endl << "and it just so ";       cout << "happens that im a quantity surveyor!" << endl << endl;   cout << "How long in meter(s) do you want this wall to be then luv??: ";   cin >> length;   cout << endl;   cout << "Yes, yes, ok your wall will be " << length << " metre's long." << endl << endl;   cout << "how many course of bricks high do you want your wall to be? ";   cin >> courses;   cout << endl;   cout << "ok your wall will have " << courses << " courses." << endl << endl;  totalbricks = 10*(length*courses);  totalprice = 6*totalbricks;     cout << "you will need about " << totalbricks << " bricks!" << endl << endl;   cout << "( I am assuming that you are using my special 10cm long bricks that";     cout <<  " you can glue together so no gap";         cout <<"or need for mortar! only \$6 EACH special offer!)" << endl << endl;   cout << "It will only cost you \$" << totalprice;   cout << ", so your looking at a real bargain!" << endl << endl;       cout << "Now be a darlin' will ya and put the kettle on... cheers" << endl << endl;     return 0;     }```

Lol, it's true, they do sound like that in Derbyshire! :-p

Sam.