need help learning c++ while loop

This is a discussion on need help learning c++ while loop within the C++ Programming forums, part of the General Programming Boards category; My preamble: sorry if my q is mundane. I'm leanring form "the complete idiot's guide" (not recomended btw). Here's the ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    20

    need help learning c++ while loop

    My preamble: sorry if my q is mundane.

    I'm leanring form "the complete idiot's guide" (not recomended btw). Here's the code they have you type, it's a runtime array:

    #include <iostream.h>
    #define max 40
    main()
    {
    int number[max];//intlz array<max ie 40
    int count=0;
    int index;
    int more;//promt user for more
    while (1)//loop to get data
    {
    cout<<"enter number ";
    cin>>number[count];//why do we need [count]
    cout<<"More y/n";
    cin>>more;
    if (more=='n')//if statment ie continue or not
    {
    break;//
    }
    else
    {
    count++;
    }
    }
    return(0);
    }

    I run it and it won't stop. As far as I can tell the else statment doesn't repeat back into the loop, but I don't know what to put in.

    Thanx in advance!

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    71
    You should define more as char, not int.


  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    20
    thanx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 11:44 AM
  2. syntax question
    By cyph1e in forum C Programming
    Replies: 19
    Last Post: 03-31-2006, 12:59 AM
  3. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 04:45 PM
  4. Loop, Loop, Loop?!
    By aprilbiz in forum C Programming
    Replies: 10
    Last Post: 07-24-2002, 05:45 AM
  5. How to change recursive loop to non recursive loop
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 06-24-2002, 09:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21