Thread: Perhaps someone can see where i am wrong?

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

    Angry Perhaps someone can see where i am wrong?

    I have agonized over this, for the past hour, i am not sure where i am going wrong, i have yet to try the while and do while loops, perhaps that is where i am going wrong.
    anyways, i am making a program that when you input a number it gives you the multiplication table(onl up to 12)for that number. well what i need is for it to ask for another number (after it has executed the first number) and repeat the process
    and if the number is over 12 to output an error.
    this is what i have(ps....i am a newbie to C++)
    #include<iostream.h>
    int main()
    {
    int k;
    float number;

    cout<<"\n Please enter a number you would like multiplied:";
    cin>>number;


    for(k=0;k<=12;++k)
    {
    cout<<k<<"*"<<number<<"="<<(k*number)<<"\t\t\n";

    }
    return 0;
    }

  2. #2
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    Code:
    int main() 
    { 
       int k; 
       float number = 1; 
       char quit='z';
    
       while((quit != 'Q')&&(quit != 'q'))
       {
       
       while ((number > 12)||(number < 0))
       {
           cout<<"\n Please enter a number from 1-12 you would like multiplied:"; 
           cin>>number;
       } // end inner while loop 
    
    
        for(k=0;k<=12;++k) 
       { 
           cout<<k<<"*"<<number<<"="<<(k*number)<<"\t\t\n"; 
    
       } 
    
       cout << "\nEnter 'Q' to quit or 'C' to continue: ";
       cin  >> quit;
    
       }//end outter while loop-loop. end program if quit = q or Q
    return 0; 
    }
    Blue

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    isn't it k++?

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    > isn't it k++?

    In that case, either one will work.

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    5

    thanks for the help, but.............

    Maybe i am not cut out for this stuff
    i am soo lost
    in my first post i wrote down what i have

    now what i need is
    for the person who is using the program to enter a number between 1-12
    dos will then display the times table
    ex:
    1*5=5
    2*5=10
    3*5=13
    .
    .
    .
    .
    .
    .
    12*5=60
    then i need to ask the person to enter another number, i need the loop to quit after 10 times(of asking for another number)
    if a number outside of 1-12, it has to display error..............if anyone can help i would be gratful, if anyon needs to see what i have check out the first post from me, i have a little more now, but its not doing what i want it too

  6. #6
    Unregistered
    Guest
    look more closely at Betazep's code. It will allow the user to input an unlimited number of choices one after the other. This is controlled by the first, or outer, while loop wherein the conditional checks to make sure that the flag, called quit, isn't the char Q or the char q. If you want to limit the user to making no more than 10 passes through the table then just add another conditional, this time using a counter which has been declared an int and which is incremented by one each time you get to the end of outer while loop's code loop and is incoporated into the conditional with another logical AND symbol -- && counter < 11--where counter is initialized to one outside either of the while loops.

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    5

    Thank you

    I would just like to say thanks for all of you replying to my post. It is really nice to come here to the message board and get many answers instead of talking to my teacher or a classmate.
    I apprieciate it alot. It all helped and i got my program working and handed it in to my teacher.
    p.s( i am brand new to learning C++)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM