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

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. Ugh... use [b]bold[/b] to outline the questions in your post. I am a programmer, not a reader.

3. 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...

4. 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. I don't agree.

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

6. Or in C, just not specify any....

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

7. 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

8. Originally Posted by master5001
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 )

9. 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!