Complaint: Disappointed

Pages: 12
This is ridiculous, I've ask one question and you guys refuse to reply? How does that help?
this is offtopic. please move this to the lounge where it is appropriate.
Okay Abby. You're presumably referring to this: http://www.cplusplus.com/forum/general/160149/

You posted your question. You got a response and an offer of help, even though your question is context-free, the code you needed help with wasn't featured in the original post, and you didn't specify what was wrong with the code. Normally, the question would go completely ignored. However, you did get an offer of help.

Yet, rather than cooperate with the person helping you, you requested that the aid run the code and find the problem, which requires minimal effort on your part. It wouldn't have been hard for you to run the program yourself and give the problem output, or better yet to give a general region of the code to look in.

Then you reposted your question without really improving it. Because the original question was bad and because you double-posted, people didn't really want to touch it, because these are signs of someone who doesn't really put any effort into getting help. And now you're posting this complaint about now getting help for your minimal effort.

We're all volunteers, and we're all unpaid. This complaint only makes us less interested in dealing with you. To increase your chances of drawing interest, please follow the guidelines here: http://www.cplusplus.com/articles/jLzyhbRD/

-Albatross

P.S. - You may want to use std::string instead of char[].
I've ask one question
You've asked a question worth a book's answer.

 http://www.cplusplus.com/forum/beginner/160158/ wrote:
I need to create a point of sale system and a inventory. The point of sake system should reduce the inventory when a(n) item/s are purchased. It should save the inventory inputted that when you exit the program it is still there, also it should print(display on screen) a receipt showing the item, quantity and cost of the items/s purchased.
 http://www.cplusplus.com/forum/general/160149/ wrote:
How do you create a point of sale system program that deducts the inventory when one/more items are purchased?
Last edited on Mar 22, 2015 at 10:59am
You have failed to understand some basic protocol about asking questions on the forum.

Everyone here is doing this out of their free time. Few of us have the desire to analyse twelve hundred line program without any concrete indication of what it is you are looking for.

If you want help, don't just post your homework assignment and expect us to jump to it.


and you guys refuse to reply?
It looks to me like TariqNeaj has made a pretty valiant effort at trying to narrow down your question to something reasonably answerable.


How does that help?
It is not just on the forum that you'll find this kind of attitude. When you ask for help, you must provide help yourself. Otherwise I could just go to Google and type "42" and get whatever answer I am looking for.


For your problem, I have not taken too hard a look at your code, but there are a few things you need to work on.

The primary, and most important, is the organization of your data. Each datum should be a record (or struct) containing information about your inventory items. You have done this partly, but then discovered difficulty in managing all the different genres of inventory types. Why not simply make the genre a part of the inventory?

1
2
3
4
5
6
struct MovieItem
{
  char genre[ 30 ];
  char name[ 30 ];
  int number_in_stock;
};

Now it is very easy to read and write inventory items from/to file. (Make some functions to do that.)

The next issue I think you ought to consider is that you are using a lot of C I/O stuff when you should be sticking to C++ I/O handling. The C stuff will mess you up. Stick to C++.

It will also help you to use a C++ std::deque to store your inventory.

 
typedef std::deque <MovieItem> MovieInventory;
1
2
3
4
5
6
7
8
9
10
int main()
{
  MovieInventory inventory;

  read_inventory_from_file( "movies.txt", inventory );
  main_menu( inventory );
  save_inventory_to_file( "movies.txt", inventory );

  return 0;
}

Now you need to choose a file format for your inventory items. How about three lines per item, like:
Cartoon
Cars
12
Action
Mission Impossible
3
Drama
Ex Machina
7

Reading and writing an inventory item is now pretty simple:

1
2
3
4
5
6
7
8
9
10
void write_inventory_to_file( std::string filename, MovieInventory& inventory )
{
  std::ofstream f( filename );
  for (auto item : inventory)
  {
    f << item.genre << "\n"
         item.name << "\n"
         item.number_in_stock << "\n\n";
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void read_inventory_from_file( std::string filename, MovieInventory& inventory )
{
  MovieItem item;
  std::string genre, name;
  std::ifstream f( filename );
  while (true)
  {
    std::getline( f, genre );
    std::getline( f, name );
    f >> item.number_in_stock;  f.ignore( 1000, '\n' );
    if (!f) break;

    if (genre.length() > 29) genre.resize( 29 );
    genre.copy( item.genre, genre.length() );
    item.genre[ genre.length() ] = '\0';

    if (name.length() > 29) name.resize( 29 );
    name.copy( item.name, name.length() );
    item.name[ name.length() ] = '\0';

    inventory.push_back( item );
  }
}

Now that you have a standard container of movie items, you can easily look through it for any genre, by name, etc.

You can also add and remove items easily enough.

Hope this helps.
@the rabitoligist ...i found it difficult to explain...for the past few weeks I've improved the program....to make it clear, the reason why I ask him to run the code was to simply go through it, hence I was going to do the explanation. So, there's a bit of a misunderstanding there. Yes, I am aware that's its voluntary work, and I'm also greatful for the assistance.

@Duoas, I an now aware that my explanation is vague. To make it clear..i did not just post my homework, that's a misunderstanding. I then found it difficult to explain what the problem was but now I'm clear to what is needed.
I really do appreciate your help, and I apologize if you guys thought that I was just shoving my projecr out there for others to do it for me.

I'll be posting the improved code shortly.
I'll just sum up what the others said about posting questions in this forum.

Here is the default approach
- (tell us what you want to do) // not needed but appriciated
- tell us how you want to do that
- post the code and show us what you tried (don't forget the code tags!)
- tell us what does not work.
(If there are compiler erros, post them)
(If you just realize that the code doesn't work on a certain part of the code, tell us)

If you need help to start solving a problem:
- tell us what you want to do
- tell us how you think it could work
- show what you've tried (don't forget the code tags!)

I think that's about it, pleace correct me if something is missing.
Last edited on
To add to @gamer2015. Dont forget the god damn code tags.
Last edited on
@TarikNeaj got that :b
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <unistd.h>

struct Movie
{
char genre[10];
char name[30];
int stock;
};
struct Movie Inventory[100];

void Sale();
FILE*MoviesPtr;
float totalcost(float price,int quantity);
float price=100;
int quantity;
int choiceo3;

char ch;
char q[10]= "Action";

char Aop1[] = "Brick Mansion";
char Aop2[] = "Stay Alive";
char Aop3[] = "Fifty Shades of grey";

int main()
{
Sale();
}


// THIS IS THE SALES FUNCTION

void Sale()
{
system("cls");
system("color 0E");


//Displays Movies Available for sale
MoviesPtr=fopen("Inventory.txt","r"); //writing the output to the file

printf("\t**** List Of Movies Available For Sale ****\n");

while((ch=fgetc(MoviesPtr))!=EOF)
{
printf("%c",ch);
}

printf("\n\n");

//----------------------------------------------------------------------


//this section below deduct the amount of stock in the file by the quantity keyed in by the user//



printf("\n\nWhich movie would you like purchase:\t");
scanf("%d",&choiceo3); //Accepts User input

while(choiceo3!=0)
{

switch(choiceo3)
{
case 1:
printf("\n You wish to purchase %s\n", Aop1);

printf("\n\nHow many copies of %s would you like to purchase?\t", Aop1);
scanf("%d", &quantity);


while((MoviesPtr)!=feof)
{
if(strcmp(Inventory[a].genre,q)==0)
{
printf("I found a match\n");

fscanf(MoviesPtr," %d\t\t%s\t %s\t\t%d\n ",b, Inventory[1].genre, Inventory[1].name, Inventory[1].stock);

printf("\n%s\t %s\t\t%d\n ",Inventory[1].genre, Inventory[1].name, Inventory[1].stock);

}
}

printf("\n The total cost of your purchase amounts to $%0.2f\t", totalcost(price,quantity));

printf(" %d\t\t%s\t %s\t\t%d\n ",b, Inventory[1].genre, Inventory[1].name, Inventory[1].stock);

printf("\n\nPress any key continue...");
getch();

break;

//----------------------------------------------------------------------------------------------

// Same as above Applies for here but i didnt fill it in because it wasnt working for case one.

case 2:
printf("\n You wish to purchase %s\n", Aop2);
printf("\n\nHow many copies of %s would you like to purchase?\t", Aop2);
scanf("%d", &quantity);


printf("\n The total cost of your purchase amounts to $%0.2f\t", totalcost(price,quantity));
printf("\n\n");
getch();

break;


case 3:
printf("\n You wish to purchase %s\n", Aop3);

printf("\n\nHow many copies of %s would you like to purchase?\t", Aop3);
scanf("%d", &quantity);

printf("\n The total cost of your purchase amounts to $%0.2f\t", totalcost(price,quantity));
printf("\n\n");

break;

case 4:

default:
printf("You Have Choosen An Incorrect Option.\n");
printf("Press any key to continue:");
getch();

system("cls");
fclose(MoviesPtr);
break;

//I Have more 20+ cases for options but i didn't post them to save space.

}// end switch case

getchar(); // is this relevant?
return; // should a value be returned?

}
}// end void sales


float totalcost(float p, int q)
{
float tc;

tc = (p*q);

return tc;
}
(I'm Using C programming language, Computer science Unit 1)

how the sales function works:
1. displays a list of movies along with amount in the array (Inventory[a].stock)
2. The user will select movie from the list displayed ( case 1 - 3)
3. The user is asked for the quantity he/she wants to purchase
4. The total cost is displayed
5. (where the problem lies)

for the final thing (number 5)
1. i want the quantity to be deducted from the array (Inventory[a].stock)
2. i want it to automatically change the quantity in stock in the file (MoviesPtr)
Code tags? As in put the code within this [ ]...right?



while((MoviesPtr)!=feof)
{
if(strcmp(Inventory[a].genre,q)==0)
{
printf("I found a match\n");

fscanf(MoviesPtr," %d\t\t%s\t %s\t\t%d\n ",b, Inventory[1].genre, Inventory[1].name, Inventory[1].stock);

printf("\n%s\t %s\t\t%d\n ",Inventory[1].genre, Inventory[1].name, Inventory[1].stock);

}
}
I want to search the file and take the movie purchased from it.... I hope I'm making everything thing that I said clear. I'm trying my best to explain. I've been working on this section since last Friday
Code tags? As in put the code within this [ ]...right?


[/code]-> as in, in between these, only the last one goes first<-[code]

you can easily do it by selecting the code and clicking the <> button to the right when you post, the first one under format:.
Thanks
Last edited on
How to read then display from a random access file?

The code tag is not working, I'm not sure if its because im using a phone.

[Code] struct shop
{
char itemname[30];
Int Amtinstock;
}Inventory;

FP=fopen("movies.txt","r");
For(a=0; a<n; a++)// n is the amount of items to be inputted

{
fscanf(FP, "%s, %d", Inventory[a].itemname, Inventory[a].Amtinstock);

printf("%s, %d", Inventory[a].itemname, Inventory[a].Amtinstock);
}
fclose(FP);
[/code]
Last edited on
The code tag is not working, I'm not sure if its because im using a phone.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
struct shop
{
char itemname[30];
Int Amtinstock;
}Inventory;

FP=fopen("movies.txt","r");
For(a=0; a<n; a++)// n is the amount of items to be inputted

{
fscanf(FP, "%s, %d", Inventory[a].itemname, Inventory[a].Amtinstock);

printf("%s, %d", Inventory[a].itemname, Inventory[a].Amtinstock);
}
fclose(FP);
Last edited on
you are capitalizing the C in code. please start a new thread instead of derailing a current one.
Sigh
> 1. i want the quantity to be deducted from the array (Inventory[a].stock)
inventory[a].stock -= quantity;
make sure that there is enough stock to cover the purchase (that you don't end with a negative number of items)

> 2. i want it to automatically change the quantity in stock in the file (MoviesPtr)
iirc, in the `inventory' array you've got all your updated data. So each time that you purchase an item simply write the whole array to file.
Pages: 12