The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Coding an assignment in C..
Discuss Coding an assignment in C.. in the C Programming forum on Dev Shed. Coding an assignment in C.. C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 22nd, 2012, 09:56 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 4
Time spent in forums: 1 h 56 m 38 sec
Reputation Power: 0
|
|
|
Coding an assignment in C..
I've been asked to do an assignment that does the following
A) input each test result (1 2 or 2), display the program display "enter result" each time the program requests another result.
B)count the number of test results of each type
C) display a summary on screen of the test result indicating the number of student who passed or failed
D)if more than 10 passed print the message "bonus to the instructor"
So far what I've managed to do, with help, is this:
Code:
#include <stdio.h>
int main ()
{
int arr[15]; //declares integer array with 15 elements
for (int i = 0; i < 15; i++) // i starts at 0, and will increase by 1 each time the loop runs
// once i reaches 15, the loop will stop executing, because arr[15] is outside of our array
{
arr[i] = (i + 1) * 100; // In your test program you assign 100 to element 0,
// 200 to element 1, and so on
// this statement takes the element number (i), adds 1, then multiplies by 100 to get 100 for element 0, 200 for element 1, etc
}
char str[] = "c program"; // this is unchanged
for (int i = 0; i < 15; i++) // same loop as used before
{
printf("%d: %d\n", i+1, arr[i]); //we want to print 2 numbers, the element number + 1 and the value in the array at that element
//so we do i+1 to get "1" to print for the value in the 0th element
}
printf("string: %s\n", str); // this is unchanged
return 0;
}
I believe it covers part "A" of the assignment, could someone direct me and give help with the rest? thanks
|

November 22nd, 2012, 10:15 AM
|
 |
Contributed User
|
|
|
|
|
> I believe it covers part "A" of the assignment, could someone direct me and give help with the rest? thanks
Your program has NO input at all, so how can it possibly deal with " input each test result (1 2 or 2), display the program display "enter result" "
Looks to me like you posted the code for your previous assignment.
|

November 22nd, 2012, 10:37 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 4
Time spent in forums: 1 h 56 m 38 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by salem > I believe it covers part "A" of the assignment, could someone direct me and give help with the rest? thanks
Your program has NO input at all, so how can it possibly deal with " input each test result (1 2 or 2), display the program display "enter result" "
Looks to me like you posted the code for your previous assignment. |
Oh...could you help me make the part A
|

November 23rd, 2012, 11:14 AM
|
 |
Contributing User
|
|
|
|
|
This comment is incorrect:
// once i reaches 15, the loop will stop executing, because arr[15] is outside of our array
The loop terminates because i would not be less than 15. arr[15] is not considered in this decision.
__________________
[code] Code tags[/code] are essential for python code!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|