problem with answer going to default?

This is a discussion on problem with answer going to default? within the C++ Programming forums, part of the General Programming Boards category; Hi all, I am just starting to learn on how to program in C++. On top of that I am ...

  1. #1
    Patrick1234
    Guest

    Question problem with answer going to default?

    Hi all,
    I am just starting to learn on how to program in C++. On top of that I am trying to learn on my own (no classes) „²(Pun). So please be patience with me.
    Below is a small snip-it from my program.

    cout<<"How Long are you takeing this loan out for?"<<endl // QUESTION #1
    <<"(in Years. Defalt is 1 and Max is 40)."<<endl;
    cin>>T;
    if (T<0 || T>40)
    T=1;
    else
    { T=T; };
    cout<<"How offten are your payments?"<<endl // QUESTION #2
    <<"1) Monthly "<<endl

    What I want it to do is:
    1. ask question 1. (DOES)
    a. if T (Question1) is greater than 40 or less than 0. T defaults to 1. (DOES).
    2. ask question 2. (DOES)
    a. Get answer to Question 2.
    i. It Does NOT, it goes automatically to the default for question 2.

    My problem is how do I get it to ask question 2 and wait for the answer with out going to the default?
    Please give me a hint on what I have to use. Not just the answer.. I would like to try and figure it out myself.

    Again thank you for all you help.

  2. #2
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    and if you put up some more code make sure that you use code tags!!!!!!!!!!

  3. #3
    Patrick1234
    Guest
    Sorry Hope this helps. If not...
    Code:
    #include <iostream.h>
    #include <stdlib.h>
    using namespace std;
    void Clear();
    
    int main()
    {
     int Qp,Tp,T;
    
    cout<<"How Long are you takeing this loan out for?"<<endl       //question 1
        <<"(in Years. Defalt is 1 and Max is 40)."<<endl;
    cin>>T;                                       //user input.
     //test question 1 to see if T = 0 thru 40.
           if (T<0 || T>40)     //if T does not = 0 thru 40
           T=1;                 // Make T = 1
           else
           { T=T; };            //else T = T .
    Clear(); //function
     //question 2
    cout<<"How offten are your payments?"<<endl
        <<"1)         Monthly  "<<endl
        <<"2)         By-weekly"<<endl
        <<"3)         Weekly   "<<endl
        <<"4)         Yearly   "<<endl
        <<"           Default is once a year (4)"<<endl;
        //output all of the above.
    cin>>Qp;        //Get user input...DOES NOT DO THIS.
    //SWITCH - CASE.....GOES TO DEFAULT??????????????
            switch(Qp)         {
               case 1:  Tp=T*12;break;
               case 2:  Tp=T*26;break;
               case 3:  Tp=T*52;break;
               default: Tp=T;break;
                      };
    //OUTPUT DOES THIS.
    cout<<"So, You would have a total of "<<Tp<<" Payments!"<<endl;
    Clear(); //function
    }
    void Clear()
    {
    system("PAUSE");
    system("CLS");
    };
    &#91;code]&#91;/code]tagged by Salem

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Is it a case of needing to flush the input buffer after the first cin?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Patrick1234
    Guest

    Unhappy

    ok......sorry my fault.
    I Probably should have been more specific.
    numbers are ok.
    but when I enter a letter i get the problem.
    so what I want it to do is if the user enters anything other than 0 thru 40 T becomes the default. then it ask question 2.






    P.S. My Brain Hurts!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Utilizing another compiled program for a task.
    By kotoroshinoto in forum C Programming
    Replies: 6
    Last Post: 06-03-2008, 02:43 PM
  2. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 05:24 PM
  3. Random Numbers...Problem With FAQ Answer
    By sitestem in forum C++ Programming
    Replies: 12
    Last Post: 04-14-2004, 10:22 AM
  4. Switching Default Buttons :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 07-02-2002, 05:08 PM
  5. problem with output
    By Garfield in forum C Programming
    Replies: 2
    Last Post: 11-18-2001, 08:34 PM

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