What does the flowchart look like?
Ready to draw?
No signup. Opens instantly in your browser.
What is the matching code?
Pseudocode
read principal, rate, years
if any value is negative then refuse
interest = principal * rate * years / 100
amount = principal + interestPython
def simple_interest(principal, rate, years):
if principal < 0 or rate < 0 or years < 0:
raise ValueError("negative")
interest = principal * rate * years / 100
return interest, principal + interestC
#include <stdio.h>
void simple_interest(double principal, double rate, double years) {
double interest, amount;
if (principal < 0 || rate < 0 || years < 0) return;
interest = principal * rate * years / 100.0;
amount = principal + interest;
printf("interest %.2f\namount %.2f\n", interest, amount);
}- Principal 1000, rate 5 percent, and 2 years gives interest 100 and amount 1100.
- Rate is a percent in this chart. A rate already written as 0.05 would need a different formula.