Jump to content
  • Advertisement
Sign in to follow this  

Confuzzled again..

This topic is 4098 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok here we go.. Im doing this program for an assignment and I just cant figure out this dynamic memory allocation. So if anyone can help me, I need to convert this program to use dynamic memory allocation.. please #include <stdio.h> #include <math.h> #include <conio.h> int userinput(void); int scan(char *input); char word[80]; int main() { int loop; int i = 0; int mark[1000]; int total = 0; float mean, scale; printf("How many students are there: "); loop = userinput(); while(i<loop) { printf("Enter mark for student %d: ",i + 1); mark = userinput(); total = total + mark; i++; } mean = total/loop; if(mean<50) { i = 0; scale = 50/mean; total = 0; printf("\nScaled Mark\n", i+1); while(i<loop) { mark = mark * scale; printf("%d\n", mark); total = total + mark; i++; } mean = total/loop; printf("\nAverage mark = %.2f",mean); }else{ printf("\nAverage mark = %.2f",mean); } getch(); } int userinput(void) { gets(word); return scan(word); } int scan(char *input) { int number; int decimalPtFound = 0; int i = 0; while(input != '\0') { if(input >= '0' && input <= '9'){ } else if(input == '.'){ decimalPtFound ++; if(decimalPtFound > 1){ printf("Invalid character '.'\n\n"); main(); } }else{ printf("Invalid character '%c'\n\n", input); main(); } i++; } sscanf(input,"%d",&number); return number; } Also if someone wants to help me figure out a way to loop the same student mark if a wrong character is entered

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!