Thread: need a little help please

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    118

    need a little help please

    ok guys this is my code it dosent appear to to what i want it to.
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main ()
    {
    int a;      
    int b;      
    int c;     
    int d;      
    b=1;
    c=a*b+b;
    d=20;
    
    cout<<"please enter to number\n";
    cin>>a;
    cin.ignore();
    
    while (c<d){
    b++;
    cout<<c;
    }
    cout<<c;
    cin.get();
    }
    it just throws 3's everywhere lol is this a valid way to use a while loop?i mean it wont do the ++ thing with b??thank you in advance

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main ()
    {
    int a;      
    int b;      
    int c;     
    int d;      
    b=1;
    c=a*b+b;
    a is unintialized at this point.

    Code:
    d=20;
    
    cout<<"please enter to number\n";
    cin>>a;
    cin.ignore();
    
    while (c<d){
    b++;
    cout<<c;
    }
    Neither c nor d are changing in this loop. As written, the b++ line does not affect how many times the loop will execute.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    c=a*b+b;
    What does 'a' equal in that statement?

    i mean it wont do the ++ thing with b?
    How do you know? What if I told you it did. How would you prove me wrong?

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    118
    Code:
    cout<<"please enter to number\n";
    cin>>a;
    cin.ignore();
    
    while (c<d){
    b++;
    cout<<c;
    }
    is there any way i can get (b++) to control the loop?
    sorry im a complete newb but i try
    Last edited by thestien; 12-05-2005 at 10:14 AM.

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    118
    7stud i compiled and ran the program and it displayed the same result over and over .
    i know what your saying though as im not displaying the result of (b)
    and sorry i dont know what order to write the code but (a) will = the input form the user.
    eventually
    i been trying to write this for a week lol
    Last edited by thestien; 12-05-2005 at 09:57 AM.

Popular pages Recent additions subscribe to a feed