Need help with C program
#2

Quote:
Originally Posted by CopKing123
Посмотреть сообщение
#include <stdio.h>
#include <conio.h>

main ()
{

float a, b, c, d, e, total;
total = a + b + c + d + e;
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

Quote:
Originally Posted by CopKing123
Посмотреть сообщение
// getting marks from the user //
printf("%s Computer: ", mark, a);
scanf("%.2f", &a);
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);
}
Reply


Messages In This Thread
Need help with C program - by CopKing123 - 26.09.2017, 12:25
Re: Need help with C program - by ]Kurence[ - 26.09.2017, 12:43
Re: Need help with C program - by CopKing123 - 26.09.2017, 12:50
Re: Need help with C program - by ]Kurence[ - 26.09.2017, 12:54
Re: Need help with C program - by CopKing123 - 26.09.2017, 12:58
Re: Need help with C program - by Gammix - 26.09.2017, 14:00
Re: Need help with C program - by CopKing123 - 26.09.2017, 16:53
Re: Need help with C program - by Dayrion - 26.09.2017, 17:05
Re: Need help with C program - by 10MIN - 26.09.2017, 17:07
Re: Need help with C program - by TakeiT - 28.09.2017, 13:35

Forum Jump:


Users browsing this thread: 3 Guest(s)