Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

lining up the values

Posted on 2011-03-22
4
Medium Priority
?
233 Views
Last Modified: 2012-05-11
I seem to be very close to an answer but this is getting me.
Windows form - VS2010 - C#
The first problem is that I'm dealing with tabulated data in the wrong kind of control but I'm stuck for output options (3rd party)

I have to out a grid of info
that is basically an hourly rate * hours worked (for the purpose of the question I've kept the numbers basic)
The code shows what I have and the image shows what I'm trying to output
Problem being that I only want to have the start of each row show the x hrs/wk and need a new line after each dollar value has been outputted.
int hoursPerWeek, payRate;
            for (payRate = 5; payRate <= 10; payRate++)
            {
                for (hoursPerWeek = 10; hoursPerWeek <= 20; hoursPerWeek++)
                {
                    string prefix = hoursPerWeek + " hrs/week: ";
                    memo.AppendText(prefix);
                    prefix = "";
                    memo.AppendText((hoursPerWeek * payRate) + "\t\t");
                    if (payRate == 10)
                    {
                        memo.AppendText("\n");
                    }
                }

Open in new window

grid.gif
0
Comment
Question by:QPR
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 2000 total points
ID: 35195696
I tried this - see the code.

Output:


10 hrs/week:             50            60            70            80            90            100            
11 hrs/week:             55            66            77            88            99            110            
12 hrs/week:             60            72            84            96            108            120            
13 hrs/week:             65            78            91            104            117            130            
14 hrs/week:             70            84            98            112            126            140            
15 hrs/week:             75            90            105            120            135            150            
16 hrs/week:             80            96            112            128            144            160            
17 hrs/week:             85            102            119            136            153            170            
18 hrs/week:             90            108            126            144            162            180            
19 hrs/week:             95            114            133            152            171            190            
20 hrs/week:             100            120            140            160            180            200            

StringBuilder memo = new StringBuilder();
            int hoursPerWeek, payRate;
            for (hoursPerWeek = 10; hoursPerWeek <= 20; hoursPerWeek++) 
            {
                string prefix = hoursPerWeek + " hrs/week: "+ "\t\t";
                memo.Append(prefix);
                for(payRate = 5; payRate <= 10; payRate++)
                {
                    memo.Append((hoursPerWeek * payRate) + "\t\t");
                    if (payRate == 10)
                    {
                        memo.AppendLine( );
                    }
                }
            }
            System.Diagnostics.Debug.WriteLine(memo.ToString());

Open in new window

0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 35195702
You may need some formatting if you want to align columns properly but this is a bit different story...
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 35195715
0
 
LVL 29

Author Closing Comment

by:QPR
ID: 35195767
perfect
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question