Thread: exercise

  1. #1
    Registered User
    Join Date
    Oct 2015
    Posts
    2

    exercise

    a)100
    b)200
    c)300
    print a+b if c=300
    print a-b if c=300

    can someone help?how i do this?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Perhaps you should start by writing a program that defines a variable named a and prints a. Then, extend the program to define a variable named b and prints a + b. Then, extend the program to define a variable named c, and if c == 300, print a + b and a - b.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Oct 2015
    Posts
    2
    Code:
    #include <stdio.h>
    int main (){
    	 int a=100,b=200,c=300;
    	if ("c==300");
    	if ("c==300");
    	printf("a-b\n");
    	printf("a+b\n");
     return 0;	
    }

    like this?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    No. You need to read your notes.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Exercise 5-17 k&R
    By BinaryProgamer in forum C Programming
    Replies: 1
    Last Post: 06-22-2013, 06:51 AM
  2. exercise help
    By ali.franco95 in forum C Programming
    Replies: 2
    Last Post: 09-24-2011, 11:02 AM
  3. An exercise from K&R
    By GL.Sam in forum C Programming
    Replies: 4
    Last Post: 05-07-2010, 09:31 AM
  4. gdb exercise!
    By MK27 in forum C Programming
    Replies: 9
    Last Post: 11-24-2008, 10:17 AM
  5. K&R Exercise 1-14
    By Lee134 in forum C Programming
    Replies: 3
    Last Post: 02-16-2006, 11:20 AM