CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2014
    Posts
    1

    need help with some coding in c++

    hi so i was given 4 task to do i just started on c++ and dont really get it so heres what the code
    i need to Extend the code such that it also counts all entered values in the range -10 to -120 inclusive.
    The code should now record the maximum and minimum values within each of the three specified ranges
    how do i do that?
    Using a for loop to input and output array values
    */

    #include <stdio.h>


    int main(void)
    {
    /* Declare an array of integers */
    int Grades[5];
    int nCount;

    /* Populate the array */
    for(nCount = 0; nCount < 5; nCount++)
    {
    printf("\nPlease enter a value for array element %d : ",nCount);
    scanf("%d",&Grades[nCount]);
    }

    printf("\n\n"); /* Just a couple of lines to add a gap */

    /* Display the array */
    for(nCount = 0; nCount < 5; nCount++) /* Note that reusing nCount */
    {
    printf("Array element %d has the value %d\n", nCount, Grades[nCount]);
    }

    return 0;
    }

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: need help with some coding in c++

    Welcome to the wonderful world of c++

    Firstly, have a look at http://forums.codeguru.com/showthrea...ork-assignment

    Are you using c++ or c? as statements like scanf() would usually be found more in a c program than in a c++ program.

    You need to determine into which range the required value lies. Once you have determined this, then you can update the counts, max and min etc for that range.

    How would you do this using paper and pen? Once you know how to do it yourself, then produce a program design that details in English (or other natural language) the steps (algorithm) required to produce the required output. Once you have done this, then code the program from the design and then test and debug the program.

    Code:
    do {
         design();
         code();
         test();
         debug();
    } while (program_not_working);
    Have fun!
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured