Discussion Locked

Please helf with my C coding

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Please check my c coding I don???t know what seem to be the problem I get the zero total always I run this program, please bare with me I???m still a beginner.
below is my program.

#include
#include

int main(int argc, char *argv[])
{

char Stname[50],Stsurname[50],Fullname[100];
int test1,test2,test3,test4,test5;
float total;
double Finalmark;
int k,i,j;

k = 0;
k = 0;
j = 0;

printf("Please Enter Your Name:\n");
scanf("%s",&Stname);

printf("Please Enter Your SurName:\n");
scanf("%s",&Stsurname);

for(k = 0;k <= 4;k++) {

if(k == 0){
printf("Please Enter Test1:\n");
scanf("%d",&test1);
//total = total + test1;
k++;
}

if(k == 1){
printf("Please Enter Test2:\n");
scanf("%d",&test2);
// total = total + test2;
k++;
}

if(k == 2){
printf("Please Enter Test3:\n");
scanf("%d",&test3);
//total = total + test3;
k++;
}

if(k == 3){
printf("Please Enter Test4:\n");
scanf("%d",&test4);
// total = total + test4;
k++;
}

if(k == 4){
printf("Please Enter Test5:\n");
scanf("%d",&test5);
//total = total + test5;
k++;
}

k++;
// total == total;
}
total = test1 + test2 + test3 + test4 + test5;
Finalmark == ((total/500)*100);
printf("Your Full Name is:%s%5s\n",Stname,Stsurname);
printf("Your total is:%d\n",total);
printf("Your Full Marks is:%d\n",Finalmark);

system("PAUSE");
return 0;
}

3 replies

by avmakamu

Please check my c coding I dont know what seem to be the problem I get the zero total always I run this program. the program should allow a user to input only five test marks and output the total, Full Marks,Name and Surname, please bare with me Im still a beginner. below is my program

#include
#include

int main(int argc, char *argv[])
{

char Stname[50],Stsurname[50],Fullname[100];
int test1,test2,test3,test4,test5;
float total;
double Finalmark;
int k,i,j;

k = 0;
k = 0;
j = 0;

printf("Please Enter Your Name:\n");
scanf("%s",&Stname);

printf("Please Enter Your SurName:\n");
scanf("%s",&Stsurname);

for(k = 0;k = 4;k++) {

if(k == 0){
printf("Please Enter Test1:\n");
scanf("%d",&test1);
//total = total + test1;
k++;
}

if(k == 1){
printf("Please Enter Test2:\n");
scanf("%d",&test2);
// total = total + test2;
k++;
}

if(k == 2){
printf("Please Enter Test3:\n");
scanf("%d",&test3);
//total = total + test3;
k++;
}

if(k == 3){
printf("Please Enter Test4:\n");
scanf("%d",&test4);
// total = total + test4;
k++;
}

if(k == 4){
printf("Please Enter Test5:\n");
scanf("%d",&test5);
//total = total + test5;
k++;
}

k++;
// total == total;
}
total = test1 + test2 + test3 + test4 + test5;
Finalmark == ((total/500)*100);
printf("Your Full Name is:%s%5s\n",Stname,Stsurname);
printf("Your total is:%d\n",total);
printf("Your Full Marks is:%d\n",Finalmark);

system("PAUSE");
return 0;
}

by john.a.wills

I don't actually know C, but I can tell that you're looping when you don't have to. If your test inputs were to an array a loop might be suitable, but for the time being I advise you to get rid of the looping and ask for each test input in turn.

This discussion is closed to new replies.