The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Absolute beginner needs help
Discuss Absolute beginner needs help in the C Programming forum on Dev Shed. Absolute beginner needs help 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:
|
|
|

December 13th, 2012, 01:48 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 4
Time spent in forums: 1 h 56 m 38 sec
Reputation Power: 0
|
|
|
Absolute beginner needs help
I'm currently doing an assignment for college, the assignment is you have to enter students names and whether they pass or fail. The way mine works is you just press 1 for a pass and 2 for a fail, although it works, I dont like it.. Could anyone help me write the code for it so if i enter a number less than 40 it prints Fail and a number 40 or more it prints Pass
Code:
/* Name: C Assignment
Author: Robert Leniston
Date: 13/12/12 */
#include <stdio.h>
int main ()
{
int i, grade, pass = 0, fail = 0, count = 0, sum = 0 ;
char str[20];
printf("Roberts Assignment\tWelcome to my C assignment, it was coded by Robert Leniston\n") ;
printf("\nEnter the first name of the student then enter it\tThen enter the second name of the student and enter it\n") ;
/*this gives instructions on what the person will do when the open the project up*/
printf("Enter the Result 1 for a Pass and 2 for a Fail\n") ; printf("\nName \t Grade \t Pass \t Fail ") ;
for( i = 1; i < 16; i++ )
{ FILE *file_ptr ; file_ptr = fopen( "data.txt", "w") ;
if( file_ptr != NULL ) printf("\n\nName: ") ;
scanf("%s%s", str) ; printf("Enter The Grade: ") ;/*allows you to enter the grade*/ scanf("%d", &grade) ;
if (grade < 1) printf("incorrect Number was Entered") ;
/*this shows when an incorrect number has been entered*/
if (grade >2) printf("incorrect Number was Entered") ; /*this shows when an incorrect number has been entered*/
if (grade == 1) printf("\t\tResult: Pass ", ++pass) ;
if (grade == 2) printf("\t\tResult: Fail ", ++fail) ;
sum = pass + fail ;
count = 15 - sum ;
} printf("\n\tStudents That Passed : %d" , pass) ;
/*prints a pass*/
printf("\tStudents That Fail : %d\n" , fail) ;/* prints a fail*/
printf("\n\tAmmount Of Students Entered :%d" , sum) ; printf("\tAmmount Of Students Missing :%d\n" , count) ;
if (pass >= 10) printf("\n\t Bonus To The Instructor!") ; /*prints bonus to the instructor if <10 students pass*/
if (pass < 10) printf("\n\t Instructor Recieves No Bonus!") ; /*prints no bonus if >10 students fail*/ return 0 ; }
|

December 13th, 2012, 02:12 PM
|
 |
Contributed User
|
|
|
|
http://forums.devshed.com/c-program...n-c-934789.html
You managed to post your code properly last time.
> Sorry the code came out like that, i dont know how to fix it
Try harder.
Consider it just a little challenge.
After all, if you can't master posting code on a forum, it doesn't bode well for learning all the intricacies of programming in general.
|

December 13th, 2012, 02:49 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 4
Time spent in forums: 1 h 56 m 38 sec
Reputation Power: 0
|
|
|
Fixed, i think..
|

December 13th, 2012, 11:19 PM
|
 |
Contributed User
|
|
|
|
> Could anyone help me write the code for it so if i enter a number less than 40 it prints Fail and a number 40 or more it prints Pass
Just how did you manage to write this code?
I mean, how are you going to cope if you can't change
Code:
if (grade == 1)
printf("\t\tResult: Pass ", ++pass);
into
Code:
if (grade >= 40)
printf("\t\tResult: Pass ", ++pass);
Which reminds me, that particular printf is the cause of one of these warnings.
Code:
$ gcc -W -Wall foo.c
foo.c: In function ‘main’:
foo.c:21:5: warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat]
foo.c:33:7: warning: too many arguments for format [-Wformat-extra-args]
foo.c:35:7: warning: too many arguments for format [-Wformat-extra-args]
|
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
|
|
|
|
|