Thread: yet more code help

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    176

    yet more code help

    my parents have thier own cleaning buisness and i am trying to make a program that will calculate how much they will charge for that much of a floor and i made this for the code and it works fine except for what they will charge it gives some huge number that i dont know where its getting it form anyways here is the code
    #include <iostream.h>

    int main()
    {
    int Width;
    int length;
    cout<<"enter a width";
    cin>>Width;
    cout<<"enter a length";
    cin>>length;
    int Area = Width * length;
    int cents;
    int cost =Area * cents;
    cout << "Width:" << Width << endl;
    cout << "Length: " << length << endl;
    cout << "Area: " << Area << endl;/* this tells you what the area of what you typed in is*/
    cout << "enter the amount of cents per square foot:";
    cin>>cents;
    cout << "total cost in cents:" << cost << endl;

    char exit=exit;
    cout<< "type exit to exit:";
    cin>>exit;
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    int cents;
    int cost =Area * cents;

    Have you ever read anywhere to always intialize your variables? When you declare the variable cents, you don't intialize it with a value, so it contains a random junk value, and cost is calculated with that junk value.

    cout << "enter the amount of cents per square foot:";
    cin>>cents;

    Those lines do nothing since you already calculated the cost earlier in your code.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    i got it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM