1
When I collect the number 14 in the input it goes into infinite looping, how can I solve this problem?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ex14
{
class Program
{
static void Main(string[] args)
{
int taxa_dada, total, s, qs;
s = 5;
qs = 0;
Console.WriteLine("Qual é a taxa:");
taxa_dada = int.Parse(Console.ReadLine());
if (taxa_dada >= 8)
{
for (; ; )
{
if (taxa_dada >= s)
{
taxa_dada -= s;
qs++;
}
else
{
if (qs > 0)
{
Console.WriteLine("Total de {0} selos: {1}", qs, s);
}
if (s == 5)
{
s = 3;
qs = 0;
}
if (taxa_dada == 0)
{
break;
}
}
}
}
else
{
Console.WriteLine("Taxa minima de 8 centavo!");
}
Console.ReadKey();
}
}
}
The ideal in these simple cases is you do a table test that quickly finds the problem. Your logic inside the
for
is in fact not correct and does not allow the loop ends unless the input is multiples of 5.– Isac
yours is (; ; ) working ?
– Marco Souza