Skip to content

Instantly share code, notes, and snippets.

@CraigRodrigues CraigRodrigues/moneymoneymoney.c Secret
Last active Aug 1, 2016

Embed
What would you like to do?
CS50x Coding Contest 2016 - Money, Money, Money
#include <stdio.h>
#include <math.h>
#include "cs50.h"
int main(void)
{
double B = GetFloat(); // balance
double R = GetFloat(); // interest rate
double N = GetInt(); // years
if (B < 0 || R < 0 || N < 0)
return 0;
double X = 1 + R;
double Y = pow(X, N);
double finalBalance = Y * B;
finalBalance = roundf(finalBalance * 100) / 100;
printf("%.2f", finalBalance);
}
@CraigRodrigues

This comment has been minimized.

Copy link
Owner Author

commented Aug 1, 2016

Use double, not float to get all correct answers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.