C# Logical Schema

Joined
Dec 22, 2024
Messages
2
Reaction score
0
Please help, I need a Logical schema after the code below
A number is initialized to 0 and displayed.
When a button is pressed, the existing number is incremented by 10 and displayed.
If the number reaches 100, it is decremented by 10 until it reaches 0.
If the number reaches 0, it is incremented by 10 until it reaches 100.
The program continues this way until it is exited.

using System;
using System.Drawing;
using System.Windows.Forms;

namespace l2
{
public partial class Form1 : Form
{
int count = 0, sp = 5, x0 = 25, y0 = 300, y1 = 301;
bool sem = true;

public Form1()
{
InitializeComponent();
}

private void label1_Click(object sender, EventArgs e)
{
}

private void button1_Click(object sender, EventArgs e)
{
using (Graphics desen = this.CreateGraphics())
{
using (SolidBrush pensula_albastra = new SolidBrush(Color.Blue))
using (SolidBrush radiera = new SolidBrush(this.BackColor))
{
desen.FillRectangle(radiera, x0, y0, sp, y1 - y0);

if (sem)
{
if (count < 100)
{
count += 10;
label1.Text = count.ToString();
y0 -= 10;
}
else
{
sem = false;
count -= 10;
label1.Text = count.ToString();
y0 += 10;
}
}
else
{
if (count > 0)
{
count -= 10;
label1.Text = count.ToString();
y0 += 10;
}
else
{
sem = true;
count += 10;
label1.Text = count.ToString();
y0 -= 10;
}
}

desen.FillRectangle(pensula_albastra, x0, y0, sp, y1 - y0);
}
}

x0 += 9;
}
}
}
 
Joined
Sep 4, 2022
Messages
158
Reaction score
16
Hi ,

by the requirements you provide, you have to add 2 if() statements


Code:
...

if(count == 0){....}
if(count == 100){....}

not that Hard !

when you have constraints in mind , write it as parts of your code
 
Joined
Jul 4, 2023
Messages
589
Reaction score
78
Have you attempted anything similar?
C#:
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        int count = 0, count_counter = 0;
        int y0 = 300, y0_counter = 0;

        public Form1()
        {
            InitializeComponent();
            label1.Text = count.ToString() + " " + y0.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (count == 0)   { count_counter = +10; y0_counter = -10; }
            if (count == 100) { count_counter = -10; y0_counter = +10; }

            count += count_counter;         
            y0 += y0_counter;
            label1.Text = count.ToString() + " " + y0.ToString();
        }
    }
}
1734999294964.png
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,260
Messages
2,571,038
Members
48,768
Latest member
first4landlord

Latest Threads

Top