Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. i really need help with this

i really need help with this

Scheduled Pinned Locked Moved C / C++ / MFC
learningdata-structureshelp
11 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_14203327
    wrote on last edited by
    #1

    Please help me with the solutions for this questions, am a beginner in C and am still learning the ropes of c programming: 1.write a method that accepts an array of integers as its parameter and returns the largest value. 2.given the enum below, write a method that accepts Gender as a parameter and returns the string "Sports" for male, "reading" for female. Otherwise return "acting". 3.Given the following marks results int [] marks = {23,14,32,15,17,35,19,12,21}; -write a for loop that will find the lowest mark -write a while loop that will find the lowest marks -write a do....while loop that will find the highest marks the programming language to be used is c

    L V D V 5 Replies Last reply
    0
    • M Member_14203327

      Please help me with the solutions for this questions, am a beginner in C and am still learning the ropes of c programming: 1.write a method that accepts an array of integers as its parameter and returns the largest value. 2.given the enum below, write a method that accepts Gender as a parameter and returns the string "Sports" for male, "reading" for female. Otherwise return "acting". 3.Given the following marks results int [] marks = {23,14,32,15,17,35,19,12,21}; -write a for loop that will find the lowest mark -write a while loop that will find the lowest marks -write a do....while loop that will find the highest marks the programming language to be used is c

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Please explain exactly what help you are asking for. But do not expect someone to do your work for you. If you do not understand the assignment then you should discuss it with your teacher.

      1 Reply Last reply
      0
      • M Member_14203327

        Please help me with the solutions for this questions, am a beginner in C and am still learning the ropes of c programming: 1.write a method that accepts an array of integers as its parameter and returns the largest value. 2.given the enum below, write a method that accepts Gender as a parameter and returns the string "Sports" for male, "reading" for female. Otherwise return "acting". 3.Given the following marks results int [] marks = {23,14,32,15,17,35,19,12,21}; -write a for loop that will find the lowest mark -write a while loop that will find the lowest marks -write a do....while loop that will find the highest marks the programming language to be used is c

        V Offline
        V Offline
        Victor Nijegorodov
        wrote on last edited by
        #3

        Is it a homework?

        M 1 Reply Last reply
        0
        • M Member_14203327

          Please help me with the solutions for this questions, am a beginner in C and am still learning the ropes of c programming: 1.write a method that accepts an array of integers as its parameter and returns the largest value. 2.given the enum below, write a method that accepts Gender as a parameter and returns the string "Sports" for male, "reading" for female. Otherwise return "acting". 3.Given the following marks results int [] marks = {23,14,32,15,17,35,19,12,21}; -write a for loop that will find the lowest mark -write a while loop that will find the lowest marks -write a do....while loop that will find the highest marks the programming language to be used is c

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Member 14203327 wrote:

          Please help me...

          What do you have so far? Around these parts, posted code usually results in critiqued code.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          M 1 Reply Last reply
          0
          • M Member_14203327

            Please help me with the solutions for this questions, am a beginner in C and am still learning the ropes of c programming: 1.write a method that accepts an array of integers as its parameter and returns the largest value. 2.given the enum below, write a method that accepts Gender as a parameter and returns the string "Sports" for male, "reading" for female. Otherwise return "acting". 3.Given the following marks results int [] marks = {23,14,32,15,17,35,19,12,21}; -write a for loop that will find the lowest mark -write a while loop that will find the lowest marks -write a do....while loop that will find the highest marks the programming language to be used is c

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            [https://www.quora.com/Difference-between-while-loops-and-for-loops-in-c-programming-language\](https://www.quora.com/Difference-between-while-loops-and-for-loops-in-c-programming-language)

            "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

            1 Reply Last reply
            0
            • D David Crow

              Member 14203327 wrote:

              Please help me...

              What do you have so far? Around these parts, posted code usually results in critiqued code.

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              M Offline
              M Offline
              Member_14203327
              wrote on last edited by
              #6

              this is the code that i had but when i run it, it gives me a 0(zero) as the answer #include //program for finding the lowest value in an array using a for loop int main (){ int marks [] = {20,30,40,50,60}, a = 0, b = 1 , lowest ; for (marks[a]

              K D 2 Replies Last reply
              0
              • M Member_14203327

                this is the code that i had but when i run it, it gives me a 0(zero) as the answer #include //program for finding the lowest value in an array using a for loop int main (){ int marks [] = {20,30,40,50,60}, a = 0, b = 1 , lowest ; for (marks[a]

                K Offline
                K Offline
                k5054
                wrote on last edited by
                #7

                Member 14203327 wrote:

                int marks [] = {20,30,40,50,60}, a = 0, b = 1 , lowest ; for (marks[a]<marks[b];b++;){

                Let's a look at your for loop. In C the for loop is defined as for( init; condition; increment). Where init is the initial condition of the loop, condition is the end loop condition - that is if the condition expression returns true false, or non-zero, and increment is an expression that defines the next step of the loop. Lets look at your for loop: **init** : marks[a] < marks[b] that's effectively a No-Op, it does evaluate to true, but it does not define the starting condition of the loop **condition** : b++ I expect you know that in C false is zero and true is any non-zero value. Therefore this expression says return the value of b (= 1), then increment b, so now b = 2. At this point, the end-condition of the loop is 1, or true. that means that that the body of the loop (the portion between { and } never gets executed.. b will continue to be incremented until it gets to INT_MAX (2147483647), at which point it will roll over to INT_MIN (-2147483646) and continue incrementing until it reaches zero. However, once the value of b reaches 5 then the expression lower = marks[a] we get the dreaded undefined behavior, which, if the computer sets itself on fire, is perfectly acceptable, according to the C standard. increment: empty expression - no action performed. That's not necessarily wrong, there's plenty of times that you might write a for loop without a increment expression. This is not one of those times. Here's a template for what you should do for your for loop - I'll assume that you do not have C99 or C11, so you need to declare your loop variables outside the for loop:

                int a; /* index into the marks array \*/
                int lowest = marks[0] /* initialize the lowest variable \*/
                for( /* initial: we already know that lowest is set to marks[0], so maybe we should set our loop variable to the next index in the array \*/ your code here;
                /* condition: We need to iterate over the entire array, so the condition will be when the loop variable a no longer points to a valid array member. The ar

                M 1 Reply Last reply
                0
                • M Member_14203327

                  this is the code that i had but when i run it, it gives me a 0(zero) as the answer #include //program for finding the lowest value in an array using a for loop int main (){ int marks [] = {20,30,40,50,60}, a = 0, b = 1 , lowest ; for (marks[a]

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  Member 14203327 wrote:

                  for (marks[a]<marks[b];b++;){

                  Among other things, this may be part of your problem. A for() loop has three components: initialization, condition, increment. Any of them can be optional. In the initialization section, you have a condition. In the condition section, you have an increment. A more straight-forward approach might look something like:

                  initialize lowest to some arbitrary high number (or assign it to the 1st number in marks, and then just loop 4 times)
                  loop 5 times
                  if the current number is less than lowest, re-assign lowest to it
                  repeat
                  print

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                  1 Reply Last reply
                  0
                  • M Member_14203327

                    Please help me with the solutions for this questions, am a beginner in C and am still learning the ropes of c programming: 1.write a method that accepts an array of integers as its parameter and returns the largest value. 2.given the enum below, write a method that accepts Gender as a parameter and returns the string "Sports" for male, "reading" for female. Otherwise return "acting". 3.Given the following marks results int [] marks = {23,14,32,15,17,35,19,12,21}; -write a for loop that will find the lowest mark -write a while loop that will find the lowest marks -write a do....while loop that will find the highest marks the programming language to be used is c

                    V Offline
                    V Offline
                    Vaclav_
                    wrote on last edited by
                    #9

                    After you figure out how to set-up the for () loop , add some debugging "scaffolding" in few places to see what your code is actually doing in each iteration of the (for) loop. Perhaps adding some basic comments would also help. Leaving variables intentionally uninitialized ( lowest ) is bad habit to get into, it will bite you when things get more complex. Happy learning.

                    //program for finding the lowest value in an array using a for loop

                    #define DEBUG

                    int main (){
                    int marks [] = {20,30,40,50,60}, a = 0, b = 1 , lowest ;
                    for (marks[a]

                    1 Reply Last reply
                    0
                    • K k5054

                      Member 14203327 wrote:

                      int marks [] = {20,30,40,50,60}, a = 0, b = 1 , lowest ; for (marks[a]<marks[b];b++;){

                      Let's a look at your for loop. In C the for loop is defined as for( init; condition; increment). Where init is the initial condition of the loop, condition is the end loop condition - that is if the condition expression returns true false, or non-zero, and increment is an expression that defines the next step of the loop. Lets look at your for loop: **init** : marks[a] < marks[b] that's effectively a No-Op, it does evaluate to true, but it does not define the starting condition of the loop **condition** : b++ I expect you know that in C false is zero and true is any non-zero value. Therefore this expression says return the value of b (= 1), then increment b, so now b = 2. At this point, the end-condition of the loop is 1, or true. that means that that the body of the loop (the portion between { and } never gets executed.. b will continue to be incremented until it gets to INT_MAX (2147483647), at which point it will roll over to INT_MIN (-2147483646) and continue incrementing until it reaches zero. However, once the value of b reaches 5 then the expression lower = marks[a] we get the dreaded undefined behavior, which, if the computer sets itself on fire, is perfectly acceptable, according to the C standard. increment: empty expression - no action performed. That's not necessarily wrong, there's plenty of times that you might write a for loop without a increment expression. This is not one of those times. Here's a template for what you should do for your for loop - I'll assume that you do not have C99 or C11, so you need to declare your loop variables outside the for loop:

                      int a; /* index into the marks array \*/
                      int lowest = marks[0] /* initialize the lowest variable \*/
                      for( /* initial: we already know that lowest is set to marks[0], so maybe we should set our loop variable to the next index in the array \*/ your code here;
                      /* condition: We need to iterate over the entire array, so the condition will be when the loop variable a no longer points to a valid array member. The ar

                      M Offline
                      M Offline
                      Member_14203327
                      wrote on last edited by
                      #10

                      thank you, it helped me to write the program properly

                      1 Reply Last reply
                      0
                      • V Victor Nijegorodov

                        Is it a homework?

                        M Offline
                        M Offline
                        Member_14203327
                        wrote on last edited by
                        #11

                        it was a cat

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups