I am writing a program using a 2D array. The user inputs 5 original price values and 5 discount rates for each price. I have the input figured out but I do not understand how to execute the process for a 2D array. I need to figure out the sales price for each original price. My process is:
amtDiscount = originalPrice * discount;
salePrice = originalPrice - amtDiscount;
I just don't understand how to do it with the array. I tried doing
amtDiscount = priceDiscount[ROWS] * priceDiscount[COLS];
but when compiling I got this error: subscripted value is neither array nor point
Here is my code:
#include <stdio.h>
#define ROWS 5
#define COLS 5
int main()
{
// Declarations
float priceDiscount[ROWS][COLS];
float originalPrice = 0.0;
float discount = 0.0;
float salePrice = 0.0;
float amtDiscount = 0.0;
int i, j = 0;
//input
for(i = 0; i < 5; i++)
{
printf("Please enter 5 original prices, price %d: ", i+1);
scanf("%f", &priceDiscount[ROWS]);
}
for(j=0; j < 5; j++)
{
printf("Please enter the discount rate for each 5 prices, discount
rate %d: ", j+1);
scanf("%f", &priceDiscount[COLS]);
}
//Process
amtDiscount = originalPrice * discount;
salePrice = originalPrice - amtDiscount;
//Output
printf("Price %%Off Sale");
/*Test Cases
Case 1
Input: $3.50, 25% Output: $3.50, 25%, $2.63
Case 2
Input: $5.25, 20% Output: $5.25, 20%, $4.20
Case 3
Input: $4.00, 50% Output: $4.00, 50%, $2.00*/
return 0;
}
Any advice is greatly appreciated! Thanks!