Skip to content

Instantly share code, notes, and snippets.

@mshafae
Created February 16, 2023 21:59
Show Gist options
  • Save mshafae/f6d31d8630589c2e8986de8ce6238350 to your computer and use it in GitHub Desktop.
Save mshafae/f6d31d8630589c2e8986de8ce6238350 to your computer and use it in GitHub Desktop.
CPSC 120 Example calculating a 15% tip.
// Gist https://gist.github.com/f6d31d8630589c2e8986de8ce6238350
#include <iostream>
int main(int argc, char const *argv[]) {
// Constant tip rate of 15% expressed as a decimal of 0.15
const double kTipRate{0.15};
std::cout << "What was the bill's sum? ";
double bill;
std::cin >> bill;
double tip_amount{bill * kTipRate};
double total_bill{bill + tip_amount};
std::cout << "The bill is $" << bill << " and " << kTipRate * 100.0
<< "% tip is $" << tip_amount << " so the total bill is $"
<< total_bill << ".\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment