<Help> Simple Pause Needed.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • da Vinci

    <Help> Simple Pause Needed.

    OK, this has got to be a simple one and yet I cannot find the answer
    in my textbook.

    How can I get a simple pause after an output line, that simply waits
    for any key to be pressed to move on?

    Basically: "Press any key to continue..."

    I beleive that I am looking for is something along the lines of a....

    cin.get

    but do not know the exact syntax for it.

    I know it is so simple.... I can make and call functions with eyes
    closed yet this illudes me...

    Thanks.
  • Mike Wahler

    #2
    Re: &lt;Help&gt; Simple Pause Needed.

    "da Vinci" <blank@blank.co m> wrote in message
    news:ekujnvkm8u fraqoo2o3i6hbu8 gfkm2v1rf@4ax.c om...[color=blue]
    > OK, this has got to be a simple one and yet I cannot find the answer
    > in my textbook.
    >
    > How can I get a simple pause after an output line, that simply waits
    > for any key to be pressed to move on?
    >
    > Basically: "Press any key to continue..."[/color]

    You can get almost that. With most systems with keyboards,
    input is 'line buffered', so your program doesn't see any
    input until the user presses the 'Enter' (aka 'return') key.
    This lets one edit the input before submitting it to the
    program. Think 'fumble-fingers', and 'backspace key' :-)

    So for such systems, you can have a 'Press Enter to continue',
    in a few different ways.

    You could use cin.get(), but I'd only use that as a prelude
    to the program's termination, since even though 'get()' only
    extracts a single character, the user could easily type in
    e.g. ten characters (or more), and those characters would
    still be waiting in a 'buffer', and be presented to the
    next input request. So you'd need extra code to discard them.
    (cin.ignore() etc.)

    I find the most useful general purpose way to do this is
    with the (nonmember) 'std::getline() ' function, which will
    extract all characters up to the first newline character, and
    store them in a std::string object. (The newline character itself
    is extracted but not stored). Then just throw the string away,
    or give it to your cat. :-)

    Example:

    #include <iostream>
    #include <string>

    void wait4user()
    {
    std::string response;
    std::cout << "Press Enter to continue";
    std::getline(st d::cin, response);
    }

    int main()
    {
    std::cout << "Hello";
    wait4user();
    std::cout << "world\n";
    wait4user();
    return 0;
    }

    [color=blue]
    >
    > I beleive that I am looking for is something along the lines of a....
    >
    > cin.get[/color]

    cin.get() would work, but has the disadvantage I cited above.
    [color=blue]
    >
    > but do not know the exact syntax for it.[/color]

    That's what books are for. :-) Any good C++ compiler
    will also provide documentation for the standard library.
    [color=blue]
    >
    > I know it is so simple.... I can make and call functions with eyes
    > closed yet this illudes me...[/color]

    Open your eyes. :-)

    HTH,
    -Mike


    Comment

    • da Vinci

      #3
      Re: &lt;Help&gt; Simple Pause Needed.

      Excellent!

      It worked like a charm.

      I didnt know that info about the cin.get and having characters in the
      buffer. Appreciate that! I bet that will save a great deal of heart
      ache in the future.

      Aw, come on.... keeping your eyes open during the ride is no fun!! :-)

      Thanks again.


      On Tue, 30 Sep 2003 22:19:06 GMT, "Mike Wahler"
      <mkwahler@mkwah ler.net> wrote:
      [color=blue]
      >"da Vinci" <blank@blank.co m> wrote in message
      >news:ekujnvkm8 ufraqoo2o3i6hbu 8gfkm2v1rf@4ax. com...[color=green]
      >> OK, this has got to be a simple one and yet I cannot find the answer
      >> in my textbook.
      >>
      >> How can I get a simple pause after an output line, that simply waits
      >> for any key to be pressed to move on?
      >>
      >> Basically: "Press any key to continue..."[/color]
      >
      >You can get almost that. With most systems with keyboards,
      >input is 'line buffered', so your program doesn't see any
      >input until the user presses the 'Enter' (aka 'return') key.
      >This lets one edit the input before submitting it to the
      >program. Think 'fumble-fingers', and 'backspace key' :-)
      >
      >So for such systems, you can have a 'Press Enter to continue',
      >in a few different ways.
      >
      >You could use cin.get(), but I'd only use that as a prelude
      >to the program's termination, since even though 'get()' only
      >extracts a single character, the user could easily type in
      >e.g. ten characters (or more), and those characters would
      >still be waiting in a 'buffer', and be presented to the
      >next input request. So you'd need extra code to discard them.
      >(cin.ignore( ) etc.)
      >
      >I find the most useful general purpose way to do this is
      >with the (nonmember) 'std::getline() ' function, which will
      >extract all characters up to the first newline character, and
      >store them in a std::string object. (The newline character itself
      >is extracted but not stored). Then just throw the string away,
      >or give it to your cat. :-)
      >
      >Example:
      >
      >#include <iostream>
      >#include <string>
      >
      >void wait4user()
      >{
      > std::string response;
      > std::cout << "Press Enter to continue";
      > std::getline(st d::cin, response);
      >}
      >
      >int main()
      >{
      > std::cout << "Hello";
      > wait4user();
      > std::cout << "world\n";
      > wait4user();
      > return 0;
      >}
      >
      >[color=green]
      >>
      >> I beleive that I am looking for is something along the lines of a....
      >>
      >> cin.get[/color]
      >
      >cin.get() would work, but has the disadvantage I cited above.
      >[color=green]
      >>
      >> but do not know the exact syntax for it.[/color]
      >
      >That's what books are for. :-) Any good C++ compiler
      >will also provide documentation for the standard library.
      >[color=green]
      >>
      >> I know it is so simple.... I can make and call functions with eyes
      >> closed yet this illudes me...[/color]
      >
      >Open your eyes. :-)
      >
      >HTH,
      >-Mike
      >[/color]

      Comment

      • Kevin Goodsell

        #4
        Re: &lt;Help&gt; Simple Pause Needed.

        da Vinci wrote:[color=blue]
        > Excellent![/color]

        Please don't top-post. Read section 5 of the FAQ for posting guidelines.



        -Kevin
        --
        My email address is valid, but changes periodically.
        To contact me please use the address from a recent posting.

        Comment

        • Jonathan Mcdougall

          #5
          Re: &lt;Help&gt; Simple Pause Needed.

          > OK, this has got to be a simple one and yet I cannot find the answer[color=blue]
          > in my textbook.
          >
          > How can I get a simple pause after an output line, that simply waits
          > for any key to be pressed to move on?
          >
          > Basically: "Press any key to continue..."
          >
          > I beleive that I am looking for is something along the lines of a....
          >
          > cin.get
          >
          > but do not know the exact syntax for it.[/color]

          There is no way in standard C++ (which is the topic of this newsgroup)
          to do something like that. The closest thing would be

          std::string dummy;
          std::cin >> dummy;

          which will wait for <enter>. If you want to detect a key without <enter>,
          you will have to use something from your implementation. For further
          informations, please ask in a newsgroup supporting your compiler.



          Comment

          • Jonathan Mcdougall

            #6
            Re: &lt;Help&gt; Simple Pause Needed.

            > > OK, this has got to be a simple one and yet I cannot find the answer[color=blue][color=green]
            > > in my textbook.
            > >
            > > How can I get a simple pause after an output line, that simply waits
            > > for any key to be pressed to move on?
            > >
            > > Basically: "Press any key to continue..."
            > >
            > > I beleive that I am looking for is something along the lines of a....
            > >
            > > cin.get
            > >
            > > but do not know the exact syntax for it.[/color]
            >
            > There is no way in standard C++ (which is the topic of this newsgroup)
            > to do something like that. The closest thing would be
            >
            > std::string dummy;
            > std::cin >> dummy;
            >
            > which will wait for <enter>. If you want to detect a key without <enter>,
            > you will have to use something from your implementation. For further
            > informations, please ask in a newsgroup supporting your compiler.[/color]




            Jonathan (pressed send to early)


            Comment

            • Mike Wahler

              #7
              Re: &lt;Help&gt; Simple Pause Needed.

              "Jonathan Mcdougall" <jonathanmcdoug all@DELyahoo.ca > wrote in message
              news:5noeb.7334 8$Wk2.1400809@w eber.videotron. net...[color=blue][color=green]
              > > OK, this has got to be a simple one and yet I cannot find the answer
              > > in my textbook.
              > >
              > > How can I get a simple pause after an output line, that simply waits
              > > for any key to be pressed to move on?
              > >
              > > Basically: "Press any key to continue..."
              > >
              > > I beleive that I am looking for is something along the lines of a....
              > >
              > > cin.get
              > >
              > > but do not know the exact syntax for it.[/color]
              >
              > There is no way in standard C++ (which is the topic of this newsgroup)
              > to do something like that. The closest thing would be
              >
              > std::string dummy;
              > std::cin >> dummy;[/color]

              Warning:

              This might be sufficient for some circumstances, but
              note that there could be a problem.

              If this construct is used in a place before subsequent
              input is requested, and if in response to the above,
              the user supplies input with embedded whitespace,
              e.g. "OK I did", only the "OK" will be extracted,
              and "I did" is still there waiting, and will be supplied
              to the next input.
              Use std::getline() instead.
              [color=blue]
              >
              > which will wait for <enter>. If you want to detect a key without <enter>,
              > you will have to use something from your implementation. For further
              > informations, please ask in a newsgroup supporting your compiler.[/color]

              Agreed.

              -Mike


              Comment

              • Mike Wahler

                #8
                Re: &lt;Help&gt; Simple Pause Needed.

                "da Vinci" <blank@blank.co m> wrote in message
                news:6q1knvsp1h kgi17i89fopq8ta q1ccn38gb@4ax.c om...[color=blue]
                > Excellent!
                >
                > It worked like a charm.
                >
                > I didnt know that info about the cin.get[/color]

                Start reading, my friend. :-)
                [color=blue]
                > and having characters in the
                > buffer.[/color]

                Perhaps I was not clear enough, but note that my
                remarks about 'buffer' were only a generalization
                about 'most systems' you're likely to encounter.

                From the program's perspective, this issue is not
                limited to just cin.get() but to all input operations.
                The reason what I showed works, is that by definition,
                std::getline() reads everything on a whole line,
                and most systems with keyboards will buffer a line
                at a time.

                The language itself knows nothing about such operating
                system buffers, and only 'sees' one character at a time
                (The OS controls and supplies these characters to your
                program).
                [color=blue]
                >Appreciate that! I bet that will save a great deal of heart
                > ache in the future.[/color]

                Glad I could help.

                BTW please don't top post. If you don't know what I'm
                talking about, see the link Kevin provided.

                -Mike


                Comment

                • da Vinci

                  #9
                  Re: &lt;Help&gt; Simple Pause Needed.

                  On Tue, 30 Sep 2003 23:49:09 GMT, "Mike Wahler"
                  <mkwahler@mkwah ler.net> wrote:
                  [color=blue]
                  >Start reading, my friend. :-)[/color]

                  I tried. :) My textbook isn't very good, IMO, and the Schildt C/C++ SE
                  reference manual does cover get() and getline(), but not to the point
                  where I could get what I wanted out of it with my 1 month of C++
                  experiance. This sure isnt Turbo Pascal. :-)
                  [color=blue]
                  >BTW please don't top post. If you don't know what I'm
                  >talking about, see the link Kevin provided.[/color]

                  Had no idea, but now that I read the FAQ link, I will ensure I do not
                  do it any longer. I must have missed it the first time I read through
                  it.

                  Thanks.

                  Comment

                  • da Vinci

                    #10
                    Re: &lt;Help&gt; Simple Pause Needed.

                    >Glad I could help.[color=blue]
                    >
                    >-Mike
                    >[/color]

                    Just in case you wanted to see how I used it, this is the program I
                    was working on. Way beyond what the assignment required, but I have
                    always gone above and beyond.

                    Hopefully I am posting the code right. I read the FAQ portion of it
                    and hope I get it right. (I hate being the new guy!!) I cut out alot
                    of the white space to save room. This is not how I format everything
                    in the code.

                    #include <iostream>
                    #include <iomanip>
                    #include <string>

                    using namespace std;

                    // Declare Functions Here

                    int Display_Main_Me nu (int);
                    void View_Totals (int, int, int, int, int);
                    int Check_Number (int);
                    void Wait ();
                    void Final_Data (int, int, int, int, int);

                    int main (int)
                    {

                    // Variables for various program functions

                    int day=1, prod_num, quantity_today= 0;
                    int prod_1=0, prod_2=0, prod_3=0, prod_4=0, prod_5=0;
                    int main_selection, good_or_bad=1;

                    // Variables for continue statements

                    char cont='N';
                    char day_done = 'N';

                    while ( day <= 7 )
                    {

                    main_selection = Display_Main_Me nu (day); // Calls Function

                    switch (main_selection )
                    {
                    case 1: // Input Data - While & Switch Loops
                    system ("cls"); // Clear Screen Command
                    cont = 'N'; // Must have to avoid infinite looping!!!
                    while (cont != 'Y' )
                    {
                    while ( good_or_bad != 0 )
                    {
                    cout << "\n\n\nEnte r product number (1-5): ";
                    cin >> prod_num;
                    good_or_bad = Check_Number(pr od_num);
                    } // Ends Inner While

                    good_or_bad = 1; // Reset it to avoid infinite looping!!!

                    cout << "Enter quantity sold on day " << day << ": ";
                    cin >> quantity_today;
                    cout << "\n\nYou sold " << quantity_today
                    << " units of product " << prod_num << ".";
                    cout << "\nIs this correct (Y/N)?";
                    cin >> cont;

                    if ( cont == 'y' ) // Sets upper case letter
                    cont = 'Y';
                    } // Ends Middle While

                    switch (prod_num) // Add Quantity to Product Count
                    {

                    case 1:
                    prod_1 = prod_1 + quantity_today;
                    break;
                    case 2:
                    prod_2 = prod_2 + quantity_today;
                    break;
                    case 3:
                    prod_3 = prod_3 + quantity_today;
                    break;
                    case 4:
                    prod_4 = prod_4 + quantity_today;
                    break;
                    case 5:
                    prod_5 = prod_5 + quantity_today;
                    break;
                    } // Ends Inner Switch

                    break;

                    case 2: // User Selected "View Totals" - Call Function
                    View_Totals (prod_1, prod_2, prod_3, prod_4, prod_5);
                    break;

                    case 3: // User Wants to Advanced One Day
                    day++;
                    break;

                    case 4: // User Wants to End Input Session
                    day = 8;
                    break;

                    } // Ends Outer Switch

                    } // Ends While

                    // Display the final sales report from the data entered.
                    Final_Data (prod_1, prod_2, prod_3, prod_4, prod_5);

                    return 0;
                    } // Ends Main

                    /*This function will be called to display the main menu
                    for the user. The variable passed out of this function
                    tells the *main* what menu the user wishes to access.*/

                    int Display_Main_Me nu (int daynum)
                    {

                    int selection;

                    system ("cls"); // Clear Screen Command

                    cout << "\n\n\nDay " << daynum;
                    cout << "\n\n*****M AIN MENU*****";
                    cout << "\n\n1: Enter Data";
                    cout << "\n2: View Current Totals";
                    cout << "\n3: Continue to day " << ( daynum + 1 );
                    cout << "\n4: End Input Session";
                    cout << "\n\n\nSelectio n: ";
                    cin >> selection;

                    return selection;

                    }

                    /*This function will be called to display the totals currently
                    on file from previous input. There is no value returned from
                    this function.*/

                    void View_Totals(int prod1,int prod2,int prod3,int prod4,int prod5)
                    {
                    system ("cls"); // Clear Screen Command
                    cout << "\n\n\nYour current totals are:" << endl;
                    cout << "\nProduct 1: " << prod1 << endl;
                    cout << "Product 2: " << prod2 << endl;
                    cout << "Product 3: " << prod3 << endl;
                    cout << "Product 4: " << prod4 << endl;
                    cout << "Product 5: " << prod5 << endl;

                    Wait(); // Creates a "Press Enter to continue" statement
                    }

                    /* This function determines whether the input product number is
                    correct. The value must be an integer between 1 and 5. If it is
                    valid, then a value of 0 is returned. If it is invalid, then a
                    value of 1 is returned.*/

                    int Check_Number(in t prodnum)
                    {
                    int return_this;

                    switch (prodnum)
                    {
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                    case 5:
                    return_this = 0;
                    break;
                    default:
                    return_this = 1;
                    break;
                    }
                    return return_this;
                    }


                    /* This function will use a string to create a pause until the user
                    hits the enter key. Any other characters entered will be ignored.*/

                    void Wait()
                    {
                    string response;
                    cout << "Press Enter to continue";
                    getline(cin, response);
                    }

                    /* This function will have the number of products passed into it.
                    From this data, it will determine the amount of each product sold
                    and total gross sales for the week. Then, it will display the data.*/

                    void Final_Data(int prod1,int prod2,int prod3,int prod4,int prod5)
                    {
                    double p1total, p2total, p3total, p4total, p5total, gross;

                    p1total = (prod1 * 2.98);
                    p2total = (prod2 * 4.50);
                    p3total = (prod3 * 9.98);
                    p4total = (prod4 * 4.49);
                    p5total = (prod5 * 6.87);
                    gross = (p1total + p2total + p3total + p4total + p5total);

                    system ("cls"); // Clear Screen

                    cout << "\n\n\nYour final sales report for this week is as follows:";

                    cout << "\n\nProduc t Number\tAmount Sold\tTotal Income";
                    cout << "\n1\t\t" << prod1 << "\t\t" << "$" << p1total;
                    cout << "\n2\t\t" << prod2 << "\t\t" << "$" << p2total;
                    cout << "\n3\t\t" << prod3 << "\t\t" << "$" << p3total;
                    cout << "\n4\t\t" << prod4 << "\t\t" << "$" << p4total;
                    cout << "\n5\t\t" << prod5 << "\t\t" << "$" << p5total;

                    cout << "\n\nYour total gross sales for this week is $" << gross
                    << "\n\n\n";
                    }

                    Comment

                    • Kevin Goodsell

                      #11
                      Re: &lt;Help&gt; Simple Pause Needed.

                      da Vinci wrote:[color=blue]
                      > On Tue, 30 Sep 2003 23:49:09 GMT, "Mike Wahler"
                      > <mkwahler@mkwah ler.net> wrote:
                      >
                      >[color=green]
                      >>Start reading, my friend. :-)[/color]
                      >
                      >
                      > I tried. :) My textbook isn't very good, IMO, and the Schildt C/C++ SE
                      > reference manual does cover get() and getline(),[/color]

                      From the alt.comp.lang.l earn.c-c++ FAQ
                      (http://www.faqs.org/faqs/C-faq/learn/):

                      13: What should I look for when picking a book to learn from?

                      [...]
                      Many C and C++ experts recommend against using ANY book written by
                      a certain Herbert Schildt. To see why, read the answer to question
                      16. [...]

                      16: Why do many experts not think very highly of Herbert Schildt's
                      books?

                      A good answer to this question could fill a book by itself. While
                      no book is perfect, Schildt's books, in the opinion of many
                      gurus, seem to positively aim to mislead learners and encourage
                      bad habits. Schildt's beautifully clear writing style only makes
                      things worse by causing many "satisfied" learners to recommend his
                      books to other learners.

                      Do take a look at the following scathing articles before deciding
                      to buy a Schildt text.



                      The above reviews are admittedly based on two of Schildt's older
                      books. However, the language they describe has not changed in the
                      intervening period, and several books written at around the same
                      time remain highly regarded.

                      The following humorous post also illustrates the general feeling
                      towards Schildt and his books.
                      Ensure top-tier performance and security with our RTOS, hypervisor, and middleware power-critical systems for vehicles, medical devices, industrial automation, and more.


                      There is exactly one and ONLY one C book bearing Schildt's name on
                      its cover that is at all recommended by many C experts - see Q 25.

                      -Kevin
                      --
                      My email address is valid, but changes periodically.
                      To contact me please use the address from a recent posting.

                      Comment

                      • Jonathan Mcdougall

                        #12
                        Re: &lt;Help&gt; Simple Pause Needed.

                        > Just in case you wanted to see how I used it, this is the program I[color=blue]
                        > was working on. Way beyond what the assignment required, but I have
                        > always gone above and beyond.[/color]

                        That is how we learn.
                        [color=blue]
                        > Hopefully I am posting the code right. I read the FAQ portion of it
                        > and hope I get it right. (I hate being the new guy!!)[/color]

                        :)
                        [color=blue]
                        >I cut out alot
                        > of the white space to save room.[/color]

                        Don't! This code is very hard to read. Do not use tabs since some
                        newsreaders (as mine) remove them, but at least indent by one or
                        two spaces.
                        [color=blue]
                        >This is not how I format everything
                        > in the code.[/color]

                        I hope so, if not, don't tell us your name :)

                        The program in general is quite cool. A couple of guidelines though :

                        1) give better names to your variables and functions
                        2) try to break your code a bit more; a function must have a
                        representative name. If the name is too general (such as do_this() ),
                        break it until its name represents exactly what it does.
                        3) too much comment is like not enough
                        4) learn about arrays and vectors
                        5) don't give up!

                        [color=blue]
                        > #include <iostream>
                        > #include <iomanip>
                        > #include <string>
                        >
                        > using namespace std;
                        >
                        > // Declare Functions Here
                        >
                        > int Display_Main_Me nu (int);
                        > void View_Totals (int, int, int, int, int);
                        > int Check_Number (int);
                        > void Wait ();
                        > void Final_Data (int, int, int, int, int);[/color]

                        <personal opinion>
                        take the habit of naming the variables even on declaration,
                        it makes things clearer for everybody
                        </personal opinion>
                        [color=blue]
                        > int main (int)[/color]

                        Nope. main() has two allowed forms :

                        int main()

                        or

                        int main(int argc, char **argv)

                        where the names are optional.
                        [color=blue]
                        > {
                        >
                        > // Variables for various program functions
                        >
                        > int day=1, prod_num, quantity_today= 0;
                        > int prod_1=0, prod_2=0, prod_3=0, prod_4=0, prod_5=0;
                        > int main_selection, good_or_bad=1;[/color]

                        take the habit of defining one variable per line and
                        to comment each of them. "various program functions" is not
                        very clear imo :)
                        [color=blue]
                        > // Variables for continue statements
                        >
                        > char cont='N';
                        > char day_done = 'N';
                        >
                        > while ( day <= 7 )
                        > {
                        >
                        > main_selection = Display_Main_Me nu (day); // Calls Function[/color]

                        Display_Main_Me nu has a misleading name. It does not
                        only display, it asks for an option and returns it. Either
                        rename your function or (preferrably) break it in two.
                        [color=blue]
                        > switch (main_selection )
                        > {
                        > case 1: // Input Data - While & Switch Loops
                        > system ("cls"); // Clear Screen Command[/color]

                        non portable, be careful. A system without 'cls' will do
                        nothing. On my system, 'cls' from the command prompt formats
                        the disk without warning. its a good thing I did not run it :)
                        [color=blue]
                        > cont = 'N'; // Must have to avoid infinite looping!!!
                        > while (cont != 'Y' )
                        > {
                        > while ( good_or_bad != 0 )[/color]

                        a variable named good_or_bad does not inform on its use..
                        [color=blue]
                        > {
                        > cout << "\n\n\nEnte r product number (1-5): ";
                        > cin >> prod_num;
                        > good_or_bad = Check_Number(pr od_num);
                        > } // Ends Inner While[/color]

                        This kind of comment is useless and only clutters the code.
                        [color=blue]
                        > good_or_bad = 1; // Reset it to avoid infinite looping!!!
                        >
                        > cout << "Enter quantity sold on day " << day << ": ";
                        > cin >> quantity_today;
                        > cout << "\n\nYou sold " << quantity_today
                        > << " units of product " << prod_num << ".";
                        > cout << "\nIs this correct (Y/N)?";
                        > cin >> cont;
                        >
                        > if ( cont == 'y' ) // Sets upper case letter
                        > cont = 'Y';[/color]

                        look out std::toupper()
                        [color=blue]
                        > } // Ends Middle While
                        >
                        > switch (prod_num) // Add Quantity to Product Count
                        > {
                        >
                        > case 1:
                        > prod_1 = prod_1 + quantity_today;
                        > break;
                        > case 2:
                        > prod_2 = prod_2 + quantity_today;
                        > break;
                        > case 3:
                        > prod_3 = prod_3 + quantity_today;
                        > break;
                        > case 4:
                        > prod_4 = prod_4 + quantity_today;
                        > break;
                        > case 5:
                        > prod_5 = prod_5 + quantity_today;
                        > break;
                        > } // Ends Inner Switch[/color]

                        mmm.. what about an array or a std::vector here (or even a std::map)?
                        If you didn't learn about them, that's ok, but know that it would
                        be a lot simpler.
                        [color=blue]
                        > break;[/color]

                        Make the previous case in a seperate function.
                        [color=blue]
                        >
                        > case 2: // User Selected "View Totals" - Call Function
                        > View_Totals (prod_1, prod_2, prod_3, prod_4, prod_5);
                        > break;
                        >
                        > case 3: // User Wants to Advanced One Day
                        > day++;
                        > break;
                        >
                        > case 4: // User Wants to End Input Session
                        > day = 8;
                        > break;
                        >
                        > } // Ends Outer Switch[/color]

                        Every case should look like these 3 : calling a function or two,
                        but that's it. If not, well.. it makes it harder to understand.
                        [color=blue]
                        > } // Ends While
                        >
                        > // Display the final sales report from the data entered.
                        > Final_Data (prod_1, prod_2, prod_3, prod_4, prod_5);
                        >
                        > return 0;
                        > } // Ends Main
                        >
                        > /*This function will be called to display the main menu
                        > for the user. The variable passed out of this function
                        > tells the *main* what menu the user wishes to access.*/
                        >
                        > int Display_Main_Me nu (int daynum)
                        > {
                        >
                        > int selection;
                        >
                        > system ("cls"); // Clear Screen Command[/color]

                        non portable
                        [color=blue]
                        > cout << "\n\n\nDay " << daynum;
                        > cout << "\n\n*****M AIN MENU*****";
                        > cout << "\n\n1: Enter Data";
                        > cout << "\n2: View Current Totals";
                        > cout << "\n3: Continue to day " << ( daynum + 1 );
                        > cout << "\n4: End Input Session";
                        > cout << "\n\n\nSelectio n: ";[/color]

                        Use std::endl instead of \n, which is not guaranteed to work
                        everywhere.
                        [color=blue]
                        > cin >> selection;
                        >
                        > return selection;
                        >
                        > }
                        >
                        > /*This function will be called to display the totals currently
                        > on file from previous input. There is no value returned from
                        > this function.*/
                        >
                        > void View_Totals(int prod1,int prod2,int prod3,int prod4,int prod5)
                        > {
                        > system ("cls"); // Clear Screen Command[/color]

                        not portable
                        [color=blue]
                        > cout << "\n\n\nYour current totals are:" << endl;
                        > cout << "\nProduct 1: " << prod1 << endl;
                        > cout << "Product 2: " << prod2 << endl;
                        > cout << "Product 3: " << prod3 << endl;
                        > cout << "Product 4: " << prod4 << endl;
                        > cout << "Product 5: " << prod5 << endl;
                        >
                        > Wait(); // Creates a "Press Enter to continue" statement
                        > }
                        >
                        > /* This function determines whether the input product number is
                        > correct. The value must be an integer between 1 and 5. If it is
                        > valid, then a value of 0 is returned. If it is invalid, then a
                        > value of 1 is returned.*/[/color]

                        When something can have two values meaning 'ok' or 'bad', use a bool
                        which can have the values 'true' or 'false' :

                        bool b = true;
                        b = false;
                        [color=blue]
                        > int Check_Number(in t prodnum)
                        > {
                        > int return_this;
                        >
                        > switch (prodnum)
                        > {
                        > case 1:
                        > case 2:
                        > case 3:
                        > case 4:
                        > case 5:[/color]

                        indicate intentional fall-through with a comment since in some cases,
                        it may not be clear if it is or not.
                        [color=blue]
                        > return_this = 0;
                        > break;
                        > default:
                        > return_this = 1;
                        > break;
                        > }
                        > return return_this;[/color]

                        What about something like

                        return (prodnum >= 1) && (prodnum <= 5);

                        assuming the function returns a bool.
                        [color=blue]
                        > }
                        >
                        >
                        > /* This function will use a string to create a pause until the user
                        > hits the enter key. Any other characters entered will be ignored.*/
                        >
                        > void Wait()
                        > {
                        > string response;
                        > cout << "Press Enter to continue";
                        > getline(cin, response);
                        > }
                        >
                        > /* This function will have the number of products passed into it.
                        > From this data, it will determine the amount of each product sold
                        > and total gross sales for the week. Then, it will display the data.*/
                        >
                        > void Final_Data(int prod1,int prod2,int prod3,int prod4,int prod5)
                        > {
                        > double p1total, p2total, p3total, p4total, p5total, gross;
                        >
                        > p1total = (prod1 * 2.98);
                        > p2total = (prod2 * 4.50);
                        > p3total = (prod3 * 9.98);
                        > p4total = (prod4 * 4.49);
                        > p5total = (prod5 * 6.87);
                        > gross = (p1total + p2total + p3total + p4total + p5total);
                        >
                        > system ("cls"); // Clear Screen
                        >
                        > cout << "\n\n\nYour final sales report for this week is as follows:";
                        >
                        > cout << "\n\nProduc t Number\tAmount Sold\tTotal Income";
                        > cout << "\n1\t\t" << prod1 << "\t\t" << "$" << p1total;
                        > cout << "\n2\t\t" << prod2 << "\t\t" << "$" << p2total;
                        > cout << "\n3\t\t" << prod3 << "\t\t" << "$" << p3total;
                        > cout << "\n4\t\t" << prod4 << "\t\t" << "$" << p4total;
                        > cout << "\n5\t\t" << prod5 << "\t\t" << "$" << p5total;
                        >
                        > cout << "\n\nYour total gross sales for this week is $" << gross
                        > << "\n\n\n";
                        > }[/color]


                        Jonathan


                        Comment

                        • Mike Wahler

                          #13
                          Re: &lt;Help&gt; Simple Pause Needed.


                          "Jonathan Mcdougall" <jonathanmcdoug all@DELyahoo.ca > wrote in message
                          news:YnNeb.8250 0$tJ6.2193865@w agner.videotron .net...
                          [color=blue][color=green]
                          > > cout << "\n\n\nSelectio n: ";[/color]
                          >
                          > Use std::endl instead of \n, which is not guaranteed to work
                          > everywhere.[/color]

                          Eh?

                          -Mike





                          Comment

                          • Jonathan Mcdougall

                            #14
                            Re: &lt;Help&gt; Simple Pause Needed.

                            > > > cout << "\n\n\nSelectio n: ";[color=blue][color=green]
                            > >
                            > > Use std::endl instead of \n, which is not guaranteed to work
                            > > everywhere.[/color]
                            >
                            > Eh?
                            >
                            > -Mike[/color]

                            Mmm.. I though \n was not portable, I should have informed myself.
                            Let me rephrase.

                            I prefer using std::endl since it is clearer than a bunch of \n.
                            It is also supposed to flush the buffer, but flushing the buffer
                            does not necessrily mean that the data is written.


                            Jonathan


                            Comment

                            • Dick Bridges

                              #15
                              C[ompletly]OT, but...


                              "Kevin Goodsell" <usenet1.spamfr ee.fusion@never box.com> wrote in message
                              news:Z6oeb.9319 $RW4.1568@newsr ead4.news.pas.e arthlink.net...[color=blue]
                              > da Vinci wrote:[color=green]
                              > > Excellent![/color]
                              >
                              > Please don't top-post. Read section 5 of the FAQ for posting guidelines.
                              >
                              > http://www.parashift.com/c++-faq-lite/
                              >
                              > -Kevin
                              > --
                              > My email address is valid, but changes periodically.
                              > To contact me please use the address from a recent posting.
                              >[/color]

                              What's the "approved" method of marking the text you're responding to when
                              the corporate-mandated, braindead reader (initials are LN) doesn't do it for
                              you. I've been using <previous></previous> but that seem hokey.



                              Posted Via Usenet.com Premium Usenet Newsgroup Services
                              ----------------------------------------------------------
                              ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
                              ----------------------------------------------------------
                              Best Usenet Service Providers 2025 ranked by Newsgroup Access Newsservers, Usenet Search, Features & Free Trial. Add VPN for privacy.

                              Comment

                              Working...