Click here to Skip to main content
15,891,033 members
Home / Discussions / C#
   

C#

 
GeneralRe: help Pin
Wes Aday29-Apr-14 14:25
professionalWes Aday29-Apr-14 14:25 
RantRe: help Pin
thatraja29-Apr-14 20:30
professionalthatraja29-Apr-14 20:30 
QuestionBeginner here. How would I go about doing this? Simple Data Entry Pin
Member 1078417429-Apr-14 11:32
Member 1078417429-Apr-14 11:32 
AnswerRe: Beginner here. How would I go about doing this? Simple Data Entry Pin
Pete O'Hanlon29-Apr-14 12:04
mvePete O'Hanlon29-Apr-14 12:04 
QuestionGenerate Rayleigh,Erlang,Exponential,Impulse,Uniform Noise in c#. Pin
Member 1053224929-Apr-14 10:55
Member 1053224929-Apr-14 10:55 
SuggestionRe: Generate Rayleigh,Erlang,Exponential,Impulse,Uniform Noise in c#. Pin
Richard MacCutchan29-Apr-14 20:23
mveRichard MacCutchan29-Apr-14 20:23 
QuestionArabic Word Problem In C# app Pin
Mohamed Abdel Rehim29-Apr-14 10:28
professionalMohamed Abdel Rehim29-Apr-14 10:28 
QuestionPopulation Data Chapter 7 Program 7 Pin
Member 1078420929-Apr-14 10:20
Member 1078420929-Apr-14 10:20 
I'm so lost..I don't even know where to begin.
This is what I need to do...

use Streamreader to get a file (USPopulation.txt)

use Methods

use listbox or listview

- 3 columns ( Year, Population, % Increase )
- Years are 1950-1990
- Populations numbers need to be formatted from file ( 100000 to 100,000 )
- % Increase is increase between current year and previous year

use textboxes to show years of:

- average increase
- greatest change
-least change

I have form built, exit and clear buttons done.

I have some code for the calculate button, but either one thing works or the other does...

C#
namespace PopData
{
public partial class FormPopData : Form    
{
const int SIZE = 39;        
const int NEW_SIZE = 39;        
int[] population = new int[SIZE];
int[] pop_diff = new int[NEW_SIZE];      
int index;                
public FormPopData()        
{            
InitializeComponent();        
}        
private void buttonCalculate_Click(object sender, EventArgs e)
{
//Open the USPopulation.txt file.
StreamReader inputFile = File.OpenText("USPopulation.txt");
//Read the data into the ListBox.
List<int> PopulationList = new List<int>();
int year = 1950;
while (!inputFile.EndOfStream)
{
PopulationList.Add(int.Parse(inputFile.ReadLine()));
}
//Close the file.
inputFile.Close();
int numberofyears = PopulationList.Count();
int average = Average(PopulationList);
textBoxAverage.Text = average.ToString();
int greatest = year + GreatestIncrease(PopulationList);
textBoxGreatest.Text = greatest.ToString();
int least = year + LeastIncrease(PopulationList);
textBoxLeast.Text = least.ToString();
}
}    
private int diff(int[] population)        
{           
//const int New_Size = 39;            
int count = 0;            
//int difference;            
try            
{                
pop_diff = new int[NEW_SIZE];                
for (int index = 1; index <= population.Length - 1; index++)                
{                   
pop_diff[count] = population[index] - population[index - 1] / populationindex - >1];                  
count += 1;              
}           
}          
catch (Exception ex)          
{              
//Display an error message.             
MessageBox.Show(ex.Message);          
}          
return pop_diff[count];     
}       
private int Average(List<int> PopulationList)      
{         
int amountofchange = 0;         
int changeinyears = 0;         
int thechange = 0;          
int currentyear = 0;          
//int numberofyears = 39;          
for (int index = 0; index < PopulationList.Count; index++)          
{              
thechange += PopulationList[index];             
currentyear = index;          
}         
amountofchange = (int)thechange / PopulationList.Count;          
return changeinyears;     
}
private int GreatestIncrease(List<int> PopulationList)       
{         
int amountofchange = 0;       
int changeinyears = 0;         
int thechange = 0;          
int currentyear = 0;          
for (int index = 1; index < PopulationList.Count(); index++)          
{              
thechange = PopulationList[index] - PopulationList[index - 1];            
currentyear = index;            
if (thechange > amountofchange)               
{                 
amountofchange = thechange;                
changeinyears = index;              
}        
}        
return changeinyears;    
}    
private int LeastIncrease(List<int> PopulationList)    
{          
int firstitem = PopulationList.First();         
int lastitem = PopulationList.Last();          
int amountofchange = (lastitem - firstitem);         
int changeinyears = 0;         
int thechange = 0;        
int currentyear = 0;        
for (int index = 1; index < PopulationList.Count(); index++)        
{              
thechange = PopulationList[index] - PopulationList[index - 1];             
currentyear = index;         
if (thechange < amountofchange)            
{               
amountofchange = thechange;             
changeinyears = index;           
}       
}       
return changeinyears;
}

SuggestionRe: Population Data Chapter 7 Program 7 Pin
Richard MacCutchan29-Apr-14 20:22
mveRichard MacCutchan29-Apr-14 20:22 
QuestionBeginner question. How do I create this? Simple data entry Pin
Member 1078417429-Apr-14 10:05
Member 1078417429-Apr-14 10:05 
AnswerRe: Beginner question. How do I create this? Simple data entry Pin
Dave Kreskowiak29-Apr-14 10:19
mveDave Kreskowiak29-Apr-14 10:19 
GeneralRe: Beginner question. How do I create this? Simple data entry Pin
Member 1078417429-Apr-14 10:30
Member 1078417429-Apr-14 10:30 
GeneralRe: Beginner question. How do I create this? Simple data entry Pin
Wes Aday29-Apr-14 13:08
professionalWes Aday29-Apr-14 13:08 
GeneralRe: Beginner question. How do I create this? Simple data entry Pin
Member 1078417429-Apr-14 14:19
Member 1078417429-Apr-14 14:19 
GeneralRe: Beginner question. How do I create this? Simple data entry Pin
Wes Aday29-Apr-14 14:24
professionalWes Aday29-Apr-14 14:24 
SuggestionRe: Beginner question. How do I create this? Simple data entry Pin
Matt T Heffron29-Apr-14 14:32
professionalMatt T Heffron29-Apr-14 14:32 
GeneralRe: Beginner question. How do I create this? Simple data entry Pin
Dave Kreskowiak30-Apr-14 2:28
mveDave Kreskowiak30-Apr-14 2:28 
AnswerRe: Beginner question. How do I create this? Simple data entry Pin
Hamza ain uddin khan4-May-14 12:21
professionalHamza ain uddin khan4-May-14 12:21 
AnswerRe: Beginner question. How do I create this? Simple data entry Pin
Member 1082060315-May-14 3:14
Member 1082060315-May-14 3:14 
QuestionHow to capture Skype voice communication by C# program using win32 function Pin
Tridip Bhattacharjee29-Apr-14 4:09
professionalTridip Bhattacharjee29-Apr-14 4:09 
AnswerRe: How to capture Skype voice communication by C# program using win32 function Pin
Pete O'Hanlon29-Apr-14 4:23
mvePete O'Hanlon29-Apr-14 4:23 
GeneralRe: How to capture Skype voice communication by C# program using win32 function Pin
Tridip Bhattacharjee29-Apr-14 20:58
professionalTridip Bhattacharjee29-Apr-14 20:58 
GeneralRe: How to capture Skype voice communication by C# program using win32 function Pin
Pete O'Hanlon29-Apr-14 21:38
mvePete O'Hanlon29-Apr-14 21:38 
GeneralRe: How to capture Skype voice communication by C# program using win32 function Pin
Tridip Bhattacharjee30-Apr-14 4:26
professionalTridip Bhattacharjee30-Apr-14 4:26 
QuestionA Query regarding Nullable types in C# PinPopular
Agent__00728-Apr-14 20:24
professionalAgent__00728-Apr-14 20:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.