first program: how many bricks do i need calculator

This is a discussion on first program: how many bricks do i need calculator within the C++ Programming forums, part of the General Programming Boards category; hi everyone, I have just created my first program in visual c++ 2008 and after many frustrating hours to make ...

  1. #1
    Registered User
    Join Date
    May 2012
    Location
    Buxton UK
    Posts
    14

    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;
         
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,542
    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??: ";
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2012
    Location
    Buxton UK
    Posts
    14
    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.

  4. #4
    Registered User
    Join Date
    May 2012
    Location
    Buxton UK
    Posts
    14
    thanks Salem. that makes sense to me. Im really over cautious still trying not to get errors hehe

  5. #5
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by Ben Atkins View Post
    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 :-)
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    2,411
    Quote Originally Posted by Ben Atkins View Post
    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.

  7. #7
    Registered User
    Join Date
    May 2012
    Location
    Buxton UK
    Posts
    14
    Hey thanks thats fixed it! Now i can see what else i can get my teeth into thanks

  8. #8
    Registered User
    Join Date
    Jun 2012
    Location
    Morden, UK
    Posts
    127
    Quote Originally Posted by Ben Atkins View Post
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with calculator program.
    By sadr in forum C Programming
    Replies: 9
    Last Post: 09-10-2009, 10:30 AM
  2. Need some help with Calculator program
    By Sshakey6791 in forum C++ Programming
    Replies: 3
    Last Post: 12-21-2008, 08:36 AM
  3. Help with Tax calculator program
    By Mshock in forum C++ Programming
    Replies: 1
    Last Post: 06-28-2006, 03:28 PM
  4. Help with calculator program.
    By banjordan in forum C++ Programming
    Replies: 1
    Last Post: 12-03-2003, 09:01 PM
  5. Please try Zero Bricks 0.8
    By cozman in forum Game Programming
    Replies: 12
    Last Post: 06-24-2002, 09:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21