Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

I need help with this C programming, they just dropped the question without no tutoring?

Write a program that:

(1) lets m = 40

(2) asks the user for two ages

(3) increases m by the first age only if the second is lower than the first

(4) displays m

2 Answers

Relevance
  • 7 months ago

    This seems such a simple program I could easily do it in Basic. 

    First, you want two inputs, A & B

    then compare A & B to see if  B is lower than A. 

    If B is lower than A, you then add B to the given M (40) and display the result

    If A is lower than B, you merely display the value of M which is 40. 

  • 7 months ago

    If "they" really gave you this assignment with no instruction, then drop the class.  You don't learn anything from a class that doesn't teach; and you don't learn anything by copy-pasting someone else's solution, either.

    If you do want to learn, and you did get some instruction, then you should be able to handle just the beginning and end parts of this.  Write a main() program, create an int variable named "m" and give it the value 40.  Then print out the value of m.

    Get that much working first.   When you can compile with no errors (or warnings!), run and get the expected output (40), then you're ready to add more to that program.

    To "ask the user for" something is a two-step process in C:

        ...print a prompt (usually with the printf() function), then

        ...read and convert the value (usually with the scanf() function).

     Worry about that *after* getting the first version working, though.  Then look through your notes or textbook for examples of using scanf().

Still have questions? Get your answers by asking now.