C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 13th, 2012, 01:48 PM
robl249 robl249 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 4 robl249 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 ; }

Reply With Quote
  #2  
Old December 13th, 2012, 02:12 PM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,840 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 19 h 19 m 34 sec
Reputation Power: 1774
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.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #3  
Old December 13th, 2012, 02:49 PM
robl249 robl249 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 4 robl249 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 56 m 38 sec
Reputation Power: 0
Fixed, i think..

Reply With Quote
  #4  
Old December 13th, 2012, 11:19 PM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,840 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 19 h 19 m 34 sec
Reputation Power: 1774
> 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]

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Absolute beginner needs help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap