Web Analytics Made Easy -
StatCounter Responses based on user input? - CodingForum


No announcement yet.

Responses based on user input?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Responses based on user input?

    Could someone please offer advice on the best way to add statements based on user input?

    To put it simply I want my code to make comments based on user input...

    If they say 1 person at party I want to say "no friends?"
    If thet say 100 to 150 people at the party I want to say "a shindig!!!"

    // beeralator
    #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? You must hit enter after answer...y/n\n\n";
            cin>> answer;
        while (answer=='y');
        cout << "Enjoy your party!  press enter to exit.";
     int beer()  
      string mystr;
      int people=0;
      float quantity=0;
      float hours=0;
      float price=0;
      int bottles=0;
      float pbottles=0;
      float cover=0;
       cout << "This program will calculate your cost or profit of alcahol for an event. A negative sign indicates a profit. Press enter to continue...";
       getline (cin,mystr);
      cout << "How many people will be attending? ";
      getline (cin,mystr);
      stringstream(mystr) >> people;
      cout << "On average 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 bottles will you buy? ";
      getline (cin,mystr);
      stringstream(mystr) >> bottles;
      cout << "Average cost per bottle? ";
      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 << "You will need this many cases... " << people*quantity*hours/24<< endl;
      cout << "You will spend this much on bottles... $"  << bottles*pbottles << endl;    
      cout << "Your total cost or profit will be... $" << people*quantity*hours/24*price+(bottles*pbottles)-(cover*people)  << endl;
    return 0;

  • #2
    Use if statements after you have collected the user input you need to determine the message.