28.09.2017, 13:35
Quote:
This is shit, you declare some uninitialized variables and then add them up?
You don't know the value, it could be anything, so "total" will contain unknown value too Why are you giving 2 params to the printf call? It will only print "mark", 'a' is unknown and not used anywhere. Also, don't use %.2f when loading value using scanf, use %f - %.2f should be used when printing it. (Btw, shouldn't you use %.02f?) Try this: Код:
#include <stdio.h> #include <conio.h> main () { float a, b, c, d, e, total; char mark[50] = "marks obtained in"; char str[30] = "\t MARKSHEET"; char name[30]; printf("Enter name: "); scanf("%s", name); //if you want to read name and surname, try this: //scanf("%[^\n]",name); // - this reads everything until \n (newline) character is encountered, therefore "Adolf Hitler" would work too. Your code would only read "Adolf" // getting marks from the user // printf("%s Computer: ", mark); scanf("%f", &a); printf("%s Physics: ", mark); scanf("%f", &b); printf("%s English: ", mark); scanf("%f", &c); printf("%s Urdu: ", mark); scanf("%f", &d); printf("%s Maths: ", mark); scanf("%f", &e); printf("Student: %s\n",name); printf("Computer: %.02f | Physics: %.02f | English %.02f | Urdu: %.02f | Maths: %.02f\n",a,b,c,d,e); total = a+b+c+d+e; printf("Total: %.02f\n",total); } |