2 Replies - 464 Views - Last Post: 27 April 2013 - 05:10 AM Rate Topic: -----

#1 unholycode  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-March 13

How to count If statements?

Posted 27 April 2013 - 04:21 AM

First I will start that this is home work.The homework is "Write a program that reads two positive integer numbers and prints how many numbers p exist between them such that the reminder of the division by 5 is 0 (inclusive). Example: p(17,25) = 2.".My question is how to count the right statements that are divided by 5.I searched around and can't find anything that will count and print how much numbers will be printed.I don't know how to formulate the If or there is another way as presented in the following example - (17,25) = 2.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _04.TwoInsDev5
{
    class TwoInsDev5
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter two positive integer nubmers:");
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            if (a > 0 && b > 0)
            {
                for (int i = a; i <= b; i++)
                {
                    if (i % 5 == 0)
                    {                        
                       
                    }

                }                
            }
            else if (a <= 0 || b <= 0)
            {
                Console.WriteLine("Please enter positive nubmers!");
            }
        }
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: How to count If statements?

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3227
  • View blog
  • Posts: 10,840
  • Joined: 12-December 12

Re: How to count If statements?

Posted 27 April 2013 - 04:28 AM

Can't find anything that will count? :dontgetit:. A variable will count if you start it at 0 and keep adding 1 to it. You could name that variable p.
Was This Post Helpful? 1
  • +
  • -

#3 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 198
  • View blog
  • Posts: 1,682
  • Joined: 13-March 10

Re: How to count If statements?

Posted 27 April 2013 - 05:10 AM

You must take care of the scenario when a > b. Maybe have an if-statement to determine which number is greater.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1