LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-15-2016, 08:10 PM   #1
FortuneTeller5000
LQ Newbie
 
Registered: Mar 2016
Posts: 6

Rep: Reputation: Disabled
How do i show zero(th) on the chart?


I'm a little proud of myself because I made a compound interest chart without just using someone elses example, but combined several different ones program models. However, I'm a little bothered because when i run the program it won't show the first year without any interest. This is the code I made:

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

int main()
{

float total, $;
int years;

//$ is amount deposited in bank//
$=20;
years=0;

while(years <= 20){
total= $*pow(1 + .15, years);
printf("%d\t%.2f\n", years++, total);

}
}

im just confused because i modeled this off code for a Celsius/Fahrenheit table i got out of a book and that table shows zero degrees celecius when you run the program:

linclude <stdio.h>
/* pri~t Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300; floatinq-point version */
maine )
{
float fahr, celsius;
int lower, upper, step;
lower = 0;
upper = 300;
step = 20;
/* lower limit of temperature table */
/*
upper limit */
/* step size */
fahr = lower;
while (fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
printf("%3.0f %6.1f\n", fahr, celsius);
fahr = fahr + step;
}

I even tried running my compound interest chart with the upper, lower, and step functions in the exact same way this pdf book example is used, but the chart always starts with 1. How can i change my code to include year year with just 20 dollars in the bank account?

Thanks
 
Old 03-15-2016, 10:12 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by FortuneTeller5000 View Post
However, I'm a little bothered because when i run the program it won't show the first year without any interest.
...
How can i change my code to include year year with just 20 dollars in the bank account?
Huh? I ran your code and the first line is
Code:
0	20.00
 
Old 03-16-2016, 05:57 PM   #3
FortuneTeller5000
LQ Newbie
 
Registered: Mar 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ntubski View Post
Huh? I ran your code and the first line is
Code:
0	20.00
oh oops, stupid thread, i just forgot to try maximizing the screen
 
Old 03-17-2016, 07:59 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
In the future, please use [code] tags to contain your code to make it more viewable.

DO NOT USE THE DOLLAR SIGN AS A VARIABLE NAME! You used "years", "fahr", a bunch of proper meaningful ones, and then that.

I'm glad you got your question answered, or rather it was already answered and you hadn't noticed.

Realize that you started by showing an interest compounding program, and segued into a temperature conversion program.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] org chart designer Steve W Linux - Software 4 04-04-2009 02:38 AM
Flow Chart diddyp20 Linux - Newbie 6 12-13-2008 09:16 AM
flow chart sw allelopath Linux - General 1 04-06-2004 06:02 AM
C RT Chart of data DaFrEQ Programming 0 02-18-2004 09:44 AM
/dev chart chrismiceli Linux - General 2 03-29-2003 03:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration