help needed..have no idea what's wrong with my coding..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<stdio.h>
#include<stdlib.h>


int i=1;
int main()
{

  int num[10];
  float midterm,final;
  int ID;

  for (i=1;i<10;i++)
  {
      printf("<< Student INFO # %i >>",num[i]);
      printf("\nEnter Student ID: %i",ID);
      scanf("%i",&ID);

      printf("\nEnter Midterm Score: %f",midterm);
      scanf("%.2f",&midterm);

      printf("\nEnter Final Score: %f\n",final);
      scanf("%.2f",&final);
  }



  return 0;
}


thanks in advance...
What makes you think something is wrong?

Do you get a compiler error? If so, what's the error?

Does it run but not do what you want? If so, what do you expect it to do and what does it actually do?
I'm betting it is running, but not doing what he is wanting because I'm getting some majorly screwy output from his code. This is the output I got when running the code under Ubuntu:

<< Student INFO # 32767 >>
Enter Student ID: 034

Enter Midterm Score: 0.00000034

Enter Final Score: 0.000000
<< Student INFO # 4195957 >>
Enter Student ID: 34
Enter Midterm Score: 0.000000


The INFO was already there instead of letting me enter it, the 0 in 034 was there, the 0.0000000 was there all I did was enter 34 again and it skipped over Final Score and went all the way to the Midterm Score prompt for the second entry. He is printing them before he ever initializes them from the user.
Last edited on by closed account z6A9GNh0
yes..my program i actually run..but it did show something like that...i'm just wondering why and where are my mistakes...
Explain what is not working in your code. Your code is working fine there is no problem, but there is some mistakes in display and scanf code.

In scanf size specifier will work only for strings not for numbers.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<stdio.h>
#include<stdlib.h>


int i=1;
int main()
{

  int num[10];
  float midterm,final;
  int ID;

  for (i=1;i<10;i++)
  {
      printf("<< Student INFO # %i >>",i);
      printf("\nEnter Student ID: ");
      scanf("%i",&ID);

      printf("\nEnter Midterm Score: ");
      scanf("%f",&midterm);

      printf("\nEnter Final Score: ");
      scanf("%f",&final);
  }


  return 0;
}


Topic archived. No new replies allowed.