First of all, let me just say that, this is the 1st time I have ever programmed in C, so please be gentle :S (although it shouldn't be that bad).
With regards to the program, I have been set a scenario to create a sales system where the user enters the numbers of "week", "units", and "price" (in pennies) as well as the product "name" (an array of chars) that was sold. The sales should be recorded for a period of 13 weeks......
so basically, to summarize, the user enters a list of sales which have been made over a period of 13 weeks. Once the sales have been entered for 13 weeks (0 - 12), the program should save the information to an external 'C' file (e.g. data1.c) and then read back the values from the same file, displaying only the week numbers and the total amount of sales (as a double) each week.
so, for example. if there was 32 packs of biscuits sold on week 11 at 20p each and there were 12 bars of chocolate sold on week 12 at 10p each, then once "13" was entered into the "week" variable, the program would stop, save all the sales info to the file, then read it back and display it in two columns ("week" and "total sales").
.....showing that, in this case, from the example above, in week 11 the total sales were 6.40 (20 * 32), and in week 12 the total sales were 1.20 (10 * 12). I hope that gives you a better idea of what I am trying to achieve.
so, here is my code so far. it allows me to enter sales, and prints out the sales that have been entered once the 13th week has been entered (I added that part while I was debugging to see if it was working correctly, but it is not required), but for some reason it wont stop as soon as "13" has been entered - which it should.
#include <stdio.h>
#include <string.h>
int main()
{
int week = 0;
int units = 0;
int price = 0;
char name[30];
int count = 13;
int i = 0;
int total = 0;
struct sale
{
int week;
int units;
int price;
char name[30];
}weekly_Sale;
do
{
scanf("%i %i %i %s", &weekly_Sale.week, &weekly_Sale.units, &weekly_Sale.price, weekly_Sale.name);
// i++;
}
while (weekly_Sale.week < 13);
for (i = 0; i < count; i++) //the unneeded part, I used for debugging
{
printf("%i %i %i %s ", weekly_Sale.week, weekly_Sale.units, weekly_Sale.price, weekly_Sale.name);
}
return 0;
}
....I know this is a stupid problem to have but I have looked in a book, and tried searching the internet but every time I try, I don't get anywhere. Also, I only have until 2 days time (Friday, around midday), and I have been driven mad :confused: so far by the development environment I have to use along with the amount of errors and things I've been getting, but I need to get this one and another one done :'( and I've been working on it for ages now, so please feel free to contribute, as soon as possible. thanks to everyone in advance.