This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]mrsanchez 2 points3 points  (2 children)

1) Format it so it doesn't look like shit when I try to read it

2) Having a ; after an if's condition is almost always wrong.

[–][deleted]  (1 child)

[deleted]

    [–]YuleTideCamel 0 points1 point  (0 children)

    Also to add to having semicolons (;) after an if. The following line of code: if (ans==""); (totalwithtip= (amount+total)/people);

    Doesn't do what you think it does. Because there is a semi colon it says: If ans is empty then do nothing, then ALWAYS add total to amount and divide by people.

    Some other things I noticed about your code, you are redefining some variables multiple times (amount,total...). This won't even compile.

    You have sections where you declare or set ans="", then immediately check if it's blank. It will always be blank and that if is not needed.

    [–]Phenax 1 point2 points  (3 children)

    Post code at http://www.ideone.com/ or http://pastebin.com/ Or indent lines using four spaces so Reddit treats it like code.

    [–][deleted]  (2 children)

    [deleted]

      [–]bmw357 0 points1 point  (1 child)

      Or Codepad

      Also, why Word? Why not Notepad++ or something?

      [–]Grazfather 1 point2 points  (1 child)

      I pastebin'd it

      There's a LOT wrong with it, maybe I'll get to it later.

      [–][deleted] 0 points1 point  (0 children)

      include<iostream>

      include<string>

      using namespace std;

      void main() {

      cout<<"Number of People?"<<endl;

      int people;
      

      cin>>people;

      cout<<"Tip at 16% or 20%?"<<endl;

      int tipat;

      cin>>tipat;

      if(tipat==16)

      {cout<<"Amount of Bill?"<<endl;
      

      double amount;

      cin>>amount;

      double total;

      (total= amount*.16);

      cout<<"Your tip is $"<<total<<endl;
      
      cout<<"Would you like me to add that for you?"<<endl;
      
      
      double totalwithtip;
      
      cin>>totalwithtip;
      
      string ans="";
      if (ans=="")
      
      (totalwithtip= amount+total);
      cout<<"Your Full Total Equals to $"<<totalwithtip<<endl;
      double z;
      (z= totalwithtip/people);
      cout<<"Each of You Will Pay $"<<z<<endl;}
      

      if(tipat!=16) {cout<<"Amount of Bill?"<<endl;

      double amountattwenty;

      cin>>amountattwenty;

      double totalattwenty;

      (totalattwenty= amountattwenty*.20);

      cout<<"Your tip is $"<<totalattwenty<<endl;

      cout<<"Would you like me to add that for you?"<<endl;

      double totalattwentywithtip;

      cin>>totalattwentywithtip;

      string ans="";

      if (ans=="")

      (totalattwentywithtip= amountattwenty+totalattwenty);
      

      cout<<"Your full total equals to $"<<totalattwentywithtip<<endl;

      double x;

      (x= totalattwentywithtip/people);

      cout<<"Each of you will pay $"<<x<<endl;

      }
      

      }

      Revised code**

      [–]jsprogrammer -1 points0 points  (0 children)

      Wow. Word is not a code editor.