Hej,
kolejne pytanie ode mnie.
Chciałbym aby mój program sprawdzał, czy podana liczba jest podzielna przez 7 i 3, lub czy jest podzielna przez 7 i niepodzielna przez 6 oraz
podzielna przez 7 lub przez 11.
Mój kod:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CzyPodzielne
{
class Program
{
static bool Sprawdz1(int a)
{
if ((a % 7 == 0) && (a % 3 == 0))
{
Console.WriteLine("Liczba jest podzielna przez 7 i 3");
return true;
}
else
return false;
}
static bool Sprawdz2(int a)
{
if ((a % 7 == 0) && (a % 6 != 0))
{
Console.WriteLine("Liczba jest podzielna przez 7 i nie jest podzielna przez 6");
return true;
}
else
return false;
}
static bool Sprawdz3(int a)
{
if ((a % 7 == 0) || (a % 11 == 0))
{
Console.WriteLine("Liczba jest podzielna przez 7 lub przez 11");
return true;
}
else
return false;
}
static void Main(string[] args)
{
Console.WriteLine("Podaj liczbe ");
try
{
Sprawdz1(Convert.ToInt32(Console.ReadLine()));
Sprawdz2(Convert.ToInt32(Console.ReadLine()));
Sprawdz3(Convert.ToInt32(Console.ReadLine()));
}
catch (Exception)
{
Console.WriteLine("Wystąpił błąd");
}
Console.ReadLine();
}
}
}
Muszą to być 3 metody oddzielne ( nie wnikając w sens polecenia).
Chciałbym aby program działał następująco: wprowadzamy liczbę, np.21
i funkcja main wywołuje po kolei metode sprawdz1, sprawdz2, sprawdz3.
Jednak tak sie nie dzieje. Mam wrażenie, że wywołuje tylko metode sprawdz1 i tyle.
Ktoś coś? ;)