codenew96
04-06-2009, 07:52 AM
Hello,
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...
code:
// stringstreams
#include <iostream>
#include <string>
#include <sstream>
#include <time.h>
using namespace std;
int beer();
int main ()
{
char answer;
do {
beer();
cout<<"Would you like to try again? y/n\n\n";
cin>> answer;
cin.ignore();
cout<<"\n";
}
while (answer=='y');
cout<<"Enjoy your party! press enter to exit.;
cin.get();
}
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;
}
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...
code:
// stringstreams
#include <iostream>
#include <string>
#include <sstream>
#include <time.h>
using namespace std;
int beer();
int main ()
{
char answer;
do {
beer();
cout<<"Would you like to try again? y/n\n\n";
cin>> answer;
cin.ignore();
cout<<"\n";
}
while (answer=='y');
cout<<"Enjoy your party! press enter to exit.;
cin.get();
}
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;
}