Web Analytics Made Easy -
StatCounter *-1 to reverse output c++ - CodingForum


No announcement yet.

*-1 to reverse output c++

  • Filter
  • Time
  • Show
Clear All
new posts

  • *-1 to reverse output c++

    New to both the forum and coding,
    I have some real ugly code I,ve piecd together and any advice is appreciated.

    my original delema was output in the form of negative or positive.

    Basicly I wanted to have the output be + for profit instead of -

    so I added a *-1 to the equastion to attempt to reverse the answer.
    this did not work but it did remove the - symbol from positive profit answers?

    can anyone tell me why? Or offer advice on how to do this correctly
    the issue is here...

    cout << "Your total cost or profit will be... $" << people*quantity*hours/24*price+(bottles*pbottles)-(cover*people)*-1 << endl;

    thanx in advance...

    // stringstreams
    #include <iostream>
    #include <string>
    #include <sstream>
    #include <time.h>
    using namespace std;
    int beer();
    int main ()
        char answer;
        do {
            cout<<"Would you like to try again? y/n\n\n";
            cin>> answer;
        while (answer=='y');
        cout<<"Enjoy your party!  press enter to exit.;
     int beer()  
      string mystr;
      int people=0;
      int quantity=0;
      int hours=0;
      int price=0;
      int bottles=0;
      int pbottles=0;
      int cover=0;
       cout << "This program will calculate your cost or profit of alcahol for an event. press enter to continue...";
       getline (cin,mystr);
      cout << "How many people will be attending? ";
      getline (cin,mystr);
      stringstream(mystr) >> people;
      cout << "How many beers will they be drinking an hour? ";
      getline (cin,mystr);
      stringstream(mystr) >> quantity;
      cout << "Average cost per case? ";
      getline (cin,mystr);
      stringstream(mystr) >> price;
      cout << "How many bottels will you buy? ";
      getline (cin,mystr);
      stringstream(mystr) >> bottles;
      cout << "Average cost per bottel? ";
      getline (cin,mystr);
      stringstream(mystr) >> pbottles;
      cout << "How long will the event last? ";
      getline (cin,mystr);
      stringstream(mystr) >> hours;
      cout << "cover charge? ";
      getline (cin,mystr);
      stringstream(mystr) >> cover;
      cout << "Your total cost or profit will be... $" << people*quantity*hours/24*price+(bottles*pbottles)-(cover*people)*-1  << endl;
    return 0;
    Last edited by oracleguy; Apr 6, 2009, 02:56 AM. Reason: Please use code tags

  • #2
    To determine the profit the equation would be more like:

    (cover*people) + (people*quantity*hours*pbottles) - (bottles/24 * price)

    This assumes pbottles is the amount you are selling the bottle for to the attendee. When you calculate profits, costs are additions and costs are subtractions. If it comes out negative it means you won't be making enough money to cover your costs.

    And you are spelling bottle wrong in your program btw.

    Edit: Your program could also check to make sure you will be buying enough bottles.


    • #3
      thanx for reply.

      I have not looked at equation yet but the cost of the bottel is included in the cover charge
      I plan on subtracting a case of required beer for each bottle bought but thats beside the point

      the issue i have is without the *-1 at end of equation the answer for a profit is -(the profit) giving the impression of a loss

      And why does the *-1 remove the - from profit?

      thanx again

      Havig rearead your post I realize I wasnt clear...

      Profit is shown as -profit
      cost is just shown if I don't add the *-1 to the end of the equasion


      I think that *-1 worked thats why I nolonger get a - before a profit result, but because there is no - sign infront of a cost result, the two results are indistinguishable from each other.....

      and yes I am spelling it wrong but it knows what I mean (smile)

      and of course I will be adding commentary to the answers such as "you need to buy some more bottels man....." based on user input
      Last edited by codenew96; Apr 6, 2009, 03:44 AM.