Yesterday I created a thread called "File Handling Problems!!"..... today within the first half an hour I have moved forward a bit (which is a relief)..... but I still have a problem.....

1.#include <stdio.h>
2.#include <string.h>
3.
4.int main()
5.{
6.  int week = 0;
7.  int units = 0;
8.  int price = 0;
9.  char name[30];
10.  int count = 13;
11.  int i = 0;
12.  //int total = 0;
13.  int total_Sale[13];
14.
15.  struct sale
16.  {
17.    int week;
18.    int units;
19.    int price;
20.    char name[30];
21.  }weekly_Sale[13];
22.
23.     for (i = 0; i < 13; i++)
24.     {
25.       scanf("%i %i %i %s", &weekly_Sale[i].week, 
26. &weekly_Sale[i].units, &weekly_Sale[i].price, 
27. weekly_Sale[i].name);
28.       //i++;
29.
30.     }
31.
32.     //while (weekly_Sale[i].week < 13);
33.
34.    for (i = 0; i < count; i++)
35.    {
36.      printf("%i %i %i %s ", weekly_Sale[i].week, 
37. weekly_Sale[i].units, weekly_Sale[i].price, weekly_Sale[i].name);
38.    }
39.  return 0;
40. }

.....the problem is where the for loop is, because it should stop the program once the number "13" has been entered and output all the values that have been stored in the struct but it doesn't stop on 13, and it doesnt stop on anything above either (e.g. 14)..... can someone please check it out and let me know what they might think the problem could be?

thanks in advance!

>it doesn't stop on 13
Clearly not, because you don't tell it to stop when the user enters "13". Both loops run exactly 13 times, and they'll do this without fail unless you break from the loop:

for ( i = 0; i < 13; i++ ) {
  /* ... */
  if ( some_value == 13 )
    break;
}

>it doesn't stop on 13
Clearly not, because you don't tell it to stop when the user enters "13". Both loops run exactly 13 times, and they'll do this without fail unless you break from the loop:

for ( i = 0; i < 13; i++ ) {
  /* ... */
  if ( some_value == 13 )
    break;
}

that works but there is still a problem with this part.....

......    if ( some_value == 13 )
}

because it still allows me to enter numbers higher than 13, which, as I've been saying from the start, I dont want to allow..... I want to only allow numbers from 0 to 12..... no higher than 12 should be allowed......

sorry, the last post was a mistake, i worked it out!

thanks for the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.