Error Handling in C (Files) -
i'm doing internal assessment computer science , i've come across brick wall. want search array code inputted user. i've implemented how search array string cant how prompt user reenter code if isnt within array. ideas? here progress how prompt user enter code stored within array? is,if incorrect code entered firs
for (j = 0; j < num_items; j++) //loop num_items times { //beginning of loop if (strcmp (array[j].code1, codenew) == 0) //if code found { //beginning of if statement price[i] = item_qty[i] * array[j].price1; //calculating ice f item printf ("price : %d", price[i]); //prints price printf ("\nenter '%s' confirm: ", array[j].itemname1); /confirming item scanf ("%s", item_name[i]); //reads item name array while (strcmp (item_name1[i], array[j].itemname1) != 0) /looping until both item names same { //begin while loop printf ("incorrect input. enter '%s' ,try again!: ", array[j].itemname1); //prompt user try again scanf ("%s", item_name[i]); //reads item name array } //end while loop total_price += price[i]; //calculation of total price //terminates loop } //end of if statement } //end of loop
simply wrap of above code in while loop, after loop if isn't found read input again stdin
Comments
Post a Comment