Help Please

This is a discussion on Help Please within the C++ Programming forums, part of the General Programming Boards category; hi, could someone give me some tips on how can i make the repeat if false has occur. for example: ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    141

    Help Please

    hi, could someone give me some tips on how can i make the repeat if false has occur.

    for example: the program must read in positive integer but if user enter incorrect type data, the computer will ask the user to re-enter number. can someone help me on this? please/

  2. #2
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    Code:
    bool ok = false;
    int num;
    
    while(!ok)
    {
        while(!(cin >> num))
        {
            cin.clear();
            cin.ignore(1000, '\n');
            cout << "Enter integer: ";
        }
        if(num < 1)
        {
            cout << "Enter positive number!";
        }
        else
        {
            ok = true;
        }
    }
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Read the FAQ, I'll bet you anything it's in there somewhere. And read this while you're at it.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Popular pages Recent additions subscribe to a feed

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