General discussion

Locked

Please helf with my C coding

By avmakamu ·
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 <stdio.h>
#include <stdlib.h>

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;
}

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Please helf with my C coding

by avmakamu In reply to Please helf with my C cod ...

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;
}

Collapse -

get rid of the loop

by john.a.wills In reply to Please helf with my C cod ...

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.

Collapse -

Please helf with my C coding

by avmakamu In reply to get rid of the loop

thanks a lot i will reconcider that

Back to Windows Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums