Thread: Need help on an assignment. TIA

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    1

    Need help on an assignment. TIA

    Hi, need help with an assignment. Here is the problem and the code the I came up with. When I run it, it displays the numbers but it duplicates the same line but with the incremented number.



    Create a
    C program that will accept 2 numbers: (Start Number and End Number) then display all numbers from the Start Number up to the End Number.

    Code:
    #include<stdio.h>int main()
    {
    int x,y,z;
    
    
    printf("Enter 1st number: ");
    scanf("%d",&x);
    printf("\nEnter 2nd number: ");
    scanf("%d",&y);
    {
    for (z=x;z<y;z++)
        printf("\nNumbers are %d to %d",z,y); 
    getch();
    }
    }


  2. #2
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    You have the right idea already.
    * Check the placement of the brackets needed for the "for" loop carefully. They aren't where they are supposed to be.
    * If you want to print each number between x and y, why print out y on each iteration?
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with my assignment
    By atlas07 in forum C++ Programming
    Replies: 4
    Last Post: 04-25-2010, 12:10 PM
  2. S2 assignment
    By pelisa in forum C++ Programming
    Replies: 1
    Last Post: 04-19-2010, 11:48 AM
  3. Replies: 3
    Last Post: 04-26-2009, 08:54 AM
  4. C Assignment help
    By aditya_t90 in forum C Programming
    Replies: 5
    Last Post: 03-28-2009, 10:54 AM
  5. Assignment
    By cYou in forum C++ Programming
    Replies: 4
    Last Post: 06-12-2003, 07:57 AM