Created
February 16, 2023 21:59
-
-
Save mshafae/f6d31d8630589c2e8986de8ce6238350 to your computer and use it in GitHub Desktop.
CPSC 120 Example calculating a 15% tip.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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