Results 1 to 4 of 4

Thread: C++ Barber Pole..

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    1
    Thanks
    0
    Thanked
    0 times in 0 posts

    C++ Barber Pole..

    Task:
    Write a program that given an input value 'N' displays 'N' rows of the form 12....N, 23....N+1, and so on - a barber poll pattern of numbers.

    As an example if the number 5 was entered, the program should display:

    12345
    23456
    34567
    45678
    56789

    Once the program is running, ask the user if they want to do it again.

    so what I have done is this..



    PHP Code:
    int main(void

    int user_input 0
    cout << "Please enter a number: "<< endl
    cin >> user_input
           for(
    int i=1;i<=user_input;i++) 

    for(
    int j=i;j<(user_input+i);j++) 

         
    cout<<j

    cout <<"\n"

    getch(); 
    return 
    0


    Then I realized in the program description it said "use multiple if statements" so now I've been at a stand still for 2 days, can someone help me correct this code? I would appreciate it greatly, thanks

  2. #2
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable
    the only place i can see any value of using an if statment is putting the whole body in a while(1) loop and put an if statment in to check if the user wishes to halt execution or continue running, even at that a switch statment would be better. I take it this is a coursework program? (only university/college programming courses try to get you to do stupid things like this)

  3. #3
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts
    It'd be possible to apply multiple if statements if there was a limit to the numeric value you can enter, therefore you could do if(user_input == 1) and so forth. Otherwise that looks fine the way it is.

  4. #4
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable
    i concour

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Santa Claus...the Untold History
    By Zak33 in forum General Discussion
    Replies: 16
    Last Post: 22-01-2005, 05:14 PM
  2. Blond Pole Dancer...
    By Spud1 in forum General Discussion
    Replies: 8
    Last Post: 08-09-2004, 10:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •