Thread: I've got the initial part but....

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    38

    I've got the initial part but....

    Code:
    #include <iostream>
    using namespace std;
    #include <conio.h>
    
    int main()
    {
    	int n;
    	int x=1;
    
    	cout << "Please ask for nonnegative integer: ";
    	cin >> n;
    	cout << endl;
    	while ((n > 0) && (x != (n + 1)))
    	     {cout << x << " ";
    	          x++;}
                    if (x = n)
                          n--;
                    else
                         { cout << x << " ";}
                   cout << endl;
         getch();
         return 0;
    }
    I'm supposed to write code that will accept a positive integer 'n' and display (ie if integer is 7):
    1 2 3 4 5 6 7
    1 2 3 4 5 6
    1 2 3 4 5
    1 2 3 4
    1 2 3
    1 2
    1

    I get the first line to print out but am a loss to get the rest of it to print.

    Suggestions please!!!
    mb
    Last edited by MB1; 03-02-2005 at 10:56 AM. Reason: Accidental send

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to get domain part from URL
    By George2 in forum C# Programming
    Replies: 2
    Last Post: 07-23-2008, 12:06 PM
  2. How to get a part of a string from a point onwards
    By pseudonoma in forum C Programming
    Replies: 2
    Last Post: 03-22-2008, 04:09 PM
  3. Replies: 9
    Last Post: 07-11-2006, 04:28 AM
  4. Can someone look over my code? part 2
    By brooklyn in forum C++ Programming
    Replies: 10
    Last Post: 04-18-2006, 06:33 AM
  5. Suspicious Pointer Conversion
    By mr_spanky202 in forum C Programming
    Replies: 35
    Last Post: 04-11-2003, 12:35 PM