Thread: C++ Ist Timer

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep Power
    0

    C++ Ist Timer


    i am confused and don't know where to turn.
    i am new attempting to understand C++. my question is this how do set up a program where i have to input a description and use a letter to represent it and also figure out the weight
    mulitply that times the price of that description to get the cost of the description? make sense? pls let me know!!! i am lost:( :(
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Austin TX yall
    Posts
    42
    Rep Power
    12
    I am pretty confused by your question can you be a lot more specific. From what i read this is what you need to do

    input description--From where the console or a file?
    assign a letter to the description?
    "Figure out the weight." Do you need to weigh it and input the number or is the computer supposed to get the weight from somewhere?

    Multiply that times the price? Where do we get a price from input from file or console?

    Please clarify so we can help.
    Thanks,

    Jonathan Cobb
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep Power
    0
    Thanks Jonathan!! ok i figured i would need to be more clear with this, so here goes:
    ENTER THE FOLLOWING:
    DESCRITPION <ENTER> A
    WEIGHT <ENTER> 2.0
    PRICE/LB. <ENTER> 1.98

    i would have to print the input information along with the total cost of the purchase.
    i hope this is a little more clear for you!! THANKS!!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Austin TX yall
    Posts
    42
    Rep Power
    12
    using cout << and cin>> you can output prompts and input information into variables that you will need to declare before you input into them.

    ie:
    Code:
    cout << "enter a description.\n";
    cin >> description;
    cout << "enter a weight\n";
    cin >>weight;
    /*do the same for price. then multiply the variables together to get a total.  you can use the cin and cout with the >> and << operators respecdtively to prompt and get input from a user.
    
    then output a line like such:
    */
    cout << " The total for "<< weight << " pounds at "<<  price <<  "per pound is , $"<< total << "./n";
    familiarize yourself with the cin and cout commands you will use them in every program.

    Good luck and just ask if you have more ?'s
    Thanks,

    Jonathan Cobb
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Austin TX yall
    Posts
    42
    Rep Power
    12
    correction on the /n for the last line of code. It needs to be "\n" this is the newline character used to advance the cursor to the next line. you can also use endl outside of quotes.
    Thanks,

    Jonathan Cobb
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep Power
    0
    Hey Jonnathan:

    i tried to run the program following your directions, however i am getting error message such "\n" is an undeclared identifier.
    where do i declare this in the program and how?
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep Power
    0
    Hey Jonnathan:

    i tried to run the program following your directions, however i am getting error message such "\n" is an undeclared identifier.
    where do i declare this in the program and how?
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep Power
    0

    Unhappy confused


    Thanks Jonathan!!!
    Now that i have gotten a little of the program completed, i have
    one issue that is killing me, putting all this together. i would like to place this in output below. i have it setup, but placing the pieces togther is the problem. you may need to print this out to look at it. it's pretty long. i will send you the second part. i hope you can help!!

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

    int main()
    {
    int weight=1;
    int price=2;
    char initial='A';
    int totalCost= weight * price;
    cout<<"enter description"<< "\n";
    cin>> initial;
    cout<< "enter weight"<<"\n";
    cin>>weight;
    cout<< "enter price"<<"\n";
    cin>>price;
    cout<<"totalCost is:"<< weight * price;

    cout<< endl;
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    8
    Rep Power
    0
    Hey Jonnathan:
    here is the second part: the output. i have to piece all this together

    /OUTPUT RESULTS


    cout<<setiosflags(ios::fixed| ios::showpoint|ios::right);
    cout<<"***********************************************" ;
    cout<<setw(65)<< "PENNY SPENDER SUPERMARKET"<<setw(10)<< endl;
    cout<<setw(30)<< "PRODUCE DEPARTMENT"<<setw(10)<<endl;
    cout<<" "<<endl;
    cout<<setw(10)<<"ITEM"<<setw(20)<<"WEIGHT"<<setw(20)<<"COST/lb"<<setw(20)<<"COST"<<endl;
    cout<<setw(7)<<"A"<<setw(20)<<endl;
    cout<<setw(7)<<"B"<<setw(20)<<endl;
    cout<<setw(7)<<"C"<<setw(20)<<endl;
    cout<<setw(7)<<"D"<<setw(20)<<endl;
    cout<<" "<<endl;
    cout<<setw(30)<< "Thank You!!"<<setw(10)<<endl;
    cout<<" "<<endl;
    cout<<"***********************************************" ;
    cout<<setprecision(2);
    cout <<endl;
    return 0;


    }
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Austin TX yall
    Posts
    42
    Rep Power
    12
    You need to hink all of it through and write out psuedocode to help you out. This is a must with any program that you will write.
    How many objects will the user be entering? if more than one, do we need to ask them how many. if there will be more than one, maybe use a loop to output the number of items that they entered? In the code below are you trying to output the weight and info for A, B, C, and D? Also use the code tags the word code surrounded by [] and closed with /code in [].looks like your are well on your way Just figure out if they can enter more than one item if so you will need some loops to output the data.

    Also i suggest you think about what data types to use for price and weight. A different type might hel you get cents as well as dollars.
    Last edited by jonnyfive; September 22nd, 2003 at 01:41 PM.
    Thanks,

    Jonathan Cobb

IMN logo majestic logo threadwatch logo seochat tools logo