CipherIS
asked on
C# dynamically increase / decrease a number
I am writing an app and I'm trying to perform a test.
I would like to dynamically change the heart rate. Start off with HeartRate = 20. Then increase and decrease it +/- 2, 3.
public class PatientDiagnostics
{
public int PersonID { get; set; }
public int HeartRate { get; set; }
}
I would like to dynamically change the heart rate. Start off with HeartRate = 20. Then increase and decrease it +/- 2, 3.
ASKER
When I add a person I would like to create it dynamically to the ressults are like:
(1) PersonID = 1, HeartRate = 20
(2) PersonID = 1, HeartRate = 18
(3) PersonID = 1, HeartRate = 22
(4) PersonID = 1, HeartRate = 18
(5) PersonID = 1, HeartRate = 19
(1) PersonID = 1, HeartRate = 20
(2) PersonID = 1, HeartRate = 18
(3) PersonID = 1, HeartRate = 22
(4) PersonID = 1, HeartRate = 18
(5) PersonID = 1, HeartRate = 19
Still not 100% clear but try this.
I have a windows app with 1 button.
See the code below
Output is like:
PersonID = 5, HearRate = 20
PersonID = 5, HearRate = 22
PersonID = 5, HearRate = 24
PersonID = 5, HearRate = 26
PersonID = 5, HearRate = 28
etc.
I have a windows app with 1 button.
See the code below
namespace Diagnostics
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int personID = 5;
int heartRateIncrement = 2;
List<PatientDiagnostics> allPatientDiagnostics = new List<PatientDiagnostics>();
for( int nextHeartRate = 20; nextHeartRate<=200; nextHeartRate = nextHeartRate+heartRateIncrement)
{
PatientDiagnostics pd = new PatientDiagnostics(personID, nextHeartRate);
allPatientDiagnostics.Add(pd);
}
// print list content:
foreach (PatientDiagnostics pd in allPatientDiagnostics)
{
System.Diagnostics.Debug.WriteLine(pd.toString());
}
}
}
public class PatientDiagnostics
{
private int _personID ;
private int _heartRate;
public int PersonID { get {return _personID;} }
public int HeartRate { get; set; }
public PatientDiagnostics(int personID, int heartRate)
{
_personID = personID;
HeartRate = heartRate;
}
public string toString()
{
return "PersonID = " + this._personID + ", HearRate = " + HeartRate;
}
}
}
Output is like:
PersonID = 5, HearRate = 20
PersonID = 5, HearRate = 22
PersonID = 5, HearRate = 24
PersonID = 5, HearRate = 26
PersonID = 5, HearRate = 28
etc.
ASKER
That looks like it would work. What I did was set the increment with a mod (%). This way it won't go to high for this fake data.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
May be you need just a "for" loop or similar...