Thread: No clue how to make a code to solve problems!

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    1

    No clue how to make a code to solve problems!

    Hi, I am new to C, I am going for computer programming at a college and so far C is one thing I do not understand. I understood the first three weeks and then boom, I lost traction. Our teacher never gives us time in the labs and we do all our tests and quizes on paper. It's ridiculous, but that's college for you. My problems revolve around reading output and making code to solve problems. I was never a math whiz so this is much harder. I have got good marks in college math back in high school, but I still have problems. I also own the book, the cheapest one which gave me even more confusion. I do not understand how to build even a small code, for a small problem. I know that

    #include<stdio.h>

    and

    main()
    {

    }

    Have to be used but sometimes include is not used and I do not even know when. I understand the way printf and scan f work but i do not understand the functions of lf, d, n, and int.
    I also do not understand double, do, do while, while and else. I know that those conditions are used when one number is either higher or smaller, then else comes in use and it will print an output accordingly. Midterm is coming up and I do not know how to do this. If some one can help me out with these three problems and explain it thoroughly I will appreaciate it alot. Thank you!


    1. (12 marks) Walkthrough the following program using the inputs given and show all output produced:

    Code:
     main()
    {       int i, num1, num2 = 5;
            double d2, d1 = 2.5;
            printf("Enter 2 values: ");
            scanf("%d %lf", &num1, &d2);
            if (num1 < num2)
                    printf("A\n");			
            else
                    printf("B\n”);
            if (num1+2 > d1)		
                    printf("x\n");
            else if (num1+2 < d1)
                    printf("y\n");	
            else
                    printf("z\n");
            while (num1 < num2)
            {       printf("num1: %d\n", num1);	
                    num1 += 3;
            }
            do
            {       i = 1;
                    printf("d1: %.1lf\n",d1);
                    for (i=2; i < 4; i++)
                            printf("i: %d\n",i);
                    d1 = d1 + 3.0;
            } while (d1 < d2);
            printf("i: %d, d1:%.1lf, num1: %d\n", i, d1, num1);
    }
    
    INPUT:	0 	6.2
    
    OUTPUT:						MEMORY























    3. (13 Marks) Write a program which prompts for and inputs a test mark which must be between 0 and 100 and displays an appropriate comment based on the mark as shown below:

    Mark Comment Rating
    80-100 Great 1
    Above 65 and below 80 Good 2
    55 and above to 65 and below Okay 3
    Below 55 Poor 4


    The following screen dialogue would be produced:

    Enter mark between 0 and 100.00: 222
    Error! Enter mark between 0 and 100.00: -22
    Error! Enter mark between 0 and 100.00: 72.5
    That mark is good!

    main() {


















    }



    5. (14 marks) Write a program that inputs marks for a class of students to get the total number of marks for the class and divides this by the number of students to get the average mark for the class and display the average. With inputs of 66 1 83 0 the following screen dialogue would be produced:

    Enter mark between 0 and 100.00: 66
    Enter another mark (1/Y, 0/N): 1
    Enter mark between 0 and 100.00: 83
    Enter another mark (1/Y, 0/N): 0
    Average of 2 students: 74

    main() {

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Ugh... use [b]bold[/b] to outline the questions in your post. I am a programmer, not a reader.

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    It's int main() not just main()

    You always need to #include a header file if you want to do anything that you can actually see. Otherwise you can't call any C or OS functions...
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Sadly, I would argue that the biggest error on that line is the lack of the void keyword. A function is implicitly an int. But in C, an empty list of parameters means any number of parameters can be used, not none.

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    I don't agree.

    If you want "any number of arguments", you have to prototype it with "..." (ellipsis).

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Or in C, just not specify any....

    Try it out. I use that fact when using GetProcAddress() out of laziness.

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    12
    http://faculty.valenciacc.edu/colin_...ngConcepts.htm

    these are video lessons that my teacher(i am also in a intro class) gave us a link to for help
    the first few videos are what you are looking for but i recommend watching quite a few of them
    the site lets you know which videos are for what so it is easy to navigate

    these videos help me get ahead of the rest of the class and i have one of the best grades in the class thanks to these videos
    Last edited by GiantFurby; 10-15-2008 at 06:29 PM.

  8. #8
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by master5001 View Post
    Sadly, I would argue that the biggest error on that line is the lack of the void keyword. A function is implicitly an int. But in C, an empty list of parameters means any number of parameters can be used, not none.
    Damn, I keep forgetting about that. C++ is more my specialty.

    So use this instead: int main( void )
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You need to view the video's recommended above, and any other C tutorials you can find on the internet. (There are several excellent ones).

    Then come back when you have a question or problem with a particular bit of code. There's simply no way to start posting up an off-the-cuff C tutorial, on a forum, and address all the needs you have.

    Good luck, and study hard!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trying to wrap up some code, having problems!
    By Akkernight in forum C++ Programming
    Replies: 2
    Last Post: 04-11-2009, 04:33 PM
  2. How Do You Solve Problems
    By manofsteel972 in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 12-04-2004, 10:25 AM
  3. Trying to make this code faster & Cramer
    By just2peachy in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2004, 10:54 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Problems to Make a Unix lib on a Win32 box.
    By Templario in forum Windows Programming
    Replies: 2
    Last Post: 11-21-2002, 02:22 AM