Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
Like Tree2Thanks

Math Help - C++ programming.

  1. #16
    Junior Member
    Joined
    Feb 2013
    From
    Canada
    Posts
    31

    Re: C++ programming.

    ok as you say
    Follow Math Help Forum on Facebook and Google+

  2. #17
    MHF Contributor
    Joined
    Oct 2009
    Posts
    5,513
    Thanks
    769

    Re: C++ programming.

    If you know arrays, a more elegant way to find totals is as follows.

    Code:
    int x;
    // Reserve 7 numbers: totals[0], ..., totals[6]; the first is not used
    // Initialize all numbers to 0
    int totals[7] = {0};
    
    for (int i = 0; i < 20; i++) {
      cout << "Please input the result of the " << i << "th toss: ";
      cin >> x;
      totals[x]++; // Increase the xth number by 1
    }
    It is recommended to place code between the [code] ... [/code] tags. The toolbar button with # inserts these tags around the selected text. Then spaces and formatting are preserved.
    Follow Math Help Forum on Facebook and Google+

Page 2 of 2 FirstFirst 12

Similar Math Help Forum Discussions

  1. Replies: 9
    Last Post: March 3rd 2013, 03:15 PM
  2. C++ programming. i need help !
    Posted in the New Users Forum
    Replies: 3
    Last Post: February 22nd 2013, 06:32 PM
  3. Programming For HP 48G+
    Posted in the Calculators Forum
    Replies: 0
    Last Post: February 3rd 2009, 03:09 AM
  4. Replies: 1
    Last Post: November 17th 2008, 03:18 AM
  5. Please help on R programming
    Posted in the Math Software Forum
    Replies: 0
    Last Post: August 16th 2008, 02:51 AM

Search Tags


/mathhelpforum @mathhelpforum