[source code] C Programming Tutorial - 15 - How to Calculate Interest

+2 Bucky Roberts · August 4, 2014


To make a view counter, you can use this to increment it easily


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int pageViews = 0;

    pageViews = pageViews + 1;
    printf("Page views: %d\n", pageViews);
    pageViews = pageViews + 1;
    printf("Page views: %d\n", pageViews);
    pageViews = pageViews + 1;
    printf("Page views: %d\n", pageViews);

    return 0;
}


To calculate interest


#include <stdio.h>
#include <stdlib.h>

int main()
{
    float balance = 100.00;

    balance *= 1.1;
    printf("My balance is: $%.2f\n", balance);
    balance *= 1.1;
    printf("My balance is: $%.2f\n", balance);
    balance *= 1.1;
    printf("My balance is: $%.2f\n", balance);
    balance *= 1.1;
    printf("My balance is: $%.2f\n", balance);

    return 0;
}


Post a Reply

Replies

Oldest  Newest  Rating
+2 Горан Куга · October 14, 2014
Yes there is you can do it with for loop.
#include <stdio.h>
#include <stdlib.h>

int main()
{
    float balance = 100;
    int loop; // variable named loop for counter.

    for(loop=1; loop<=50; loop++){ // with for loop we are gonna tell our computer start at 1, finish at 50, increment our variable int by one.
        balance *= 1.1;
       printf("Balance: %f \n", balance);
    }

    system("pause"); // this line is saying to our computer to pause after execute.
    return 0;
}
0 Ass Cold · October 13, 2014
Bucky is there a short way to do this without re-entering.
Lets say I want to show the next 50 years, but I don't want to c/p "printf("Balance: %f \n", balance);" 50 times. do you know what I mean?
Are there a simple code just set for showing the next 50 years only?


balance *= 1.1;
    printf("Balance: %f \n", balance);
    balance *= 1.1;
    printf("Balance: %f \n", balance);
    balance *= 1.1;
    printf("Balance: %f \n", balance);
  • 1

C

124,482 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator