dan_t Posted November 15, 2009 Share Posted November 15, 2009 OK, here's my question, how is this code formatting a table? class Program { static void Main(string[] args) { Console.Write("Please input your name: "); string employeeName = Console.ReadLine(); Console.Write("Please input your salary: "); string inputSalary = Console.ReadLine(); double salary = int.Parse(inputSalary); double balance5Percent = 0.0; double balance10Percent = 0.0; double balance15Percent = 0.0; Console.WriteLine(); Console.WriteLine("{0} at your current salary of {1:C} these are your expected balances", employeeName, salary); Console.WriteLine(); Console.WriteLine(" 5% 10% 15%"); Console.WriteLine("========================================================="); for (int i = 1; i < 40; i++) { balance5Percent = (salary * 0.05 + balance5Percent) * 1.08; balance10Percent = (salary * 0.10 + balance10Percent) * 1.08; balance15Percent = (salary * 0.15 + balance15Percent) * 1.08; if ((i % 10) == 0) { Console.WriteLine(" Year {0} {1:C} {2,14:f} {3,14:C}", i, balance5Percent, balance10Percent, balance15Percent); } } Console.WriteLine("========================================================="); Console.ReadLine(); } } } This is code from a class I am taking, but do not worry, this is not a question from the class. I would just like to know how to restructure it (the table). In order to restructure I have to understand how it is being structured in the first place. I could use the help. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/181559-c/ Share on other sites More sharing options...
KevinM1 Posted November 15, 2009 Share Posted November 15, 2009 To be honest, I'm not sure what you're asking. The program takes in some input, and calculates the money earned on that data via interest for 39 years. There's no real formatting per se, as everything is simply spewed back out to standard output. Each line has some formatting - to currency, or a specifically given floating point precision - but that's it. You should ensure your conversions from string to int to double all work. The compiler can get picky with that sort of thing. Quote Link to comment https://forums.phpfreaks.com/topic/181559-c/#findComment-957782 Share on other sites More sharing options...
dan_t Posted November 15, 2009 Author Share Posted November 15, 2009 using System; using System.Collections.Generic; using System.Text; namespace lab3a { class Program { static void Main(string[] args) { Console.Write("Please input your name: "); string employeeName = Console.ReadLine(); Console.Write("Please input your salary: "); string inputSalary = Console.ReadLine(); double salary = int.Parse(inputSalary); double balance5Percent = 0.0; double balance10Percent = 0.0; double balance15Percent = 0.0; Console.WriteLine(); Console.WriteLine("{0} at your current salary of {1:C} these are your expected balances", employeeName, salary); Console.WriteLine(); Console.WriteLine(" 5% 10% 15%"); Console.WriteLine("========================================================="); for (int i = 1; i <= 40; i++) { balance5Percent = (salary * 0.05 + balance5Percent) * 1.08; balance10Percent = (salary * 0.10 + balance10Percent) * 1.08; balance15Percent = (salary * 0.15 + balance15Percent) * 1.08; if ((i % 10) == 0) { Console.WriteLine(" Year {0} {1:C} {2,14:f} {3,14:C}", i, balance5Percent, balance10Percent, balance15Percent); } } Console.WriteLine("========================================================="); Console.ReadLine(); } } } This formats in 5, 10, and 15% across a table, but how do I go 5% for 10, 20, 30 ,40 years across the table(so to speak). I can't figure it out. Any help wold be appreciated. Thank Quote Link to comment https://forums.phpfreaks.com/topic/181559-c/#findComment-957946 Share on other sites More sharing options...
KevinM1 Posted November 15, 2009 Share Posted November 15, 2009 Remove the 10% and 15% from the loop? You're practically there, as you test the modulus of 'i' during the loop in order to output the results every 10 years. Simply remove the unneeded information and calculations. Quote Link to comment https://forums.phpfreaks.com/topic/181559-c/#findComment-958001 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.