c - Basic Food Bank program help needed -


I have a problem with the code given below for the option 2, which is the request every time I have given the user pending Instead of showing the requests, I print a request table, gives me a random high number. Can anyone help me find this problem? This code should be similar to 1 option, but it should not add user input, if there is only one request. Example output: 1 milk 20 1 milk 20 2 milk 10 2 milk 5 4 donation: milk 40 request: milk 10 milk 5

this is mine Code

  int main () {int don_count = 0, don_amt [100], found, i, don_quant, option, req_count = 0, req_amt [100], req_quant; Four words [20], don_in_ppr [100] [20], rake_world [20], rake_inw_prop [100] [20]; Printf ("Welcome to the Food Bank Program!); Printf (" 1. Enter a donation \ n2. Enter a request \ n3. Complete the request soon \ n4. Print status report \ n5.Exit \ n " ); scanf ("% d", and option); while (option! = 5) {// submit the deposit. (option == 1) {scanf ("% s", word); scanf ("% d ", & amp;; (don_in_type [i], word) == 0) found = i;} if (found ==-99); =); = () {strcpy (don_inv_type [i], word); don_amt [i] = don_quant; don_count ++;} and don_amt [found] + = don_quant;} and if (option == 2) {scanf ("% s", req_word); Scanf ("% d", and req_quant) ; req_count ++; for (i = 0; i & lt ; req_count; i ++) {strcpy (req_inv_type [i], req_word); req_amt [i] + = req_quant;}} and if (option == 3) {} else if (option == 4) {printf (" For charity: \ n "); for (i = 0; i    

you always start req_amt So, req_amt [i] + = req_quant is adding req_quant to whatever was garbage at those memory locations.

You need to do something like this:

  int req_amt [100] = {0}; ^^^^^^ & lt; --- Add this to   

or manually start the elements in some other way.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -