I am a newbie to c++... Today I was handed a assignment on "array"...While working on this...I've met plenty of errors... I wonder where did my steps gone wrong...
May anyone out there borrow me a helping hand??
#include <iostream>
#include <iomanip>
using namespace std;
float calpricetopay(int[5],float[5]); // function declaration for price to pay.
float caldiscountprice(float[5],float[5]); // function declaration for discounted price.
float calpriceafterdiscount(float[5],float[5]); //function declaration for Price after Discount
int main()
{
int stocknumber[5],quantity[5],count=1,backwardcount=2,i;
float price[5],discount[5],discountprice[5],pricetopay[5],priceafterdiscount[5];
cout.setf (ios::fixed);
cout.setf (ios::showpoint);
cout.precision (2);
for (i=1,i<=5,i++)
{
while (count<=3)
{
cout<<"Please enter the stock number."<<endl;
cin>>stocknumber[i];
if ((stocknumber>=1) && (stocknumber<=9999))
break;
if ((stocknumber<=0) || (stocknumber>=10000))
cout<<"The number you entered is invalid. Please reenter another stock number."<<endl;
cout<<"You have"<<setw(2)<<backwardcount<<setw(2)<<" chance(s) left"<<endl;
backwardcount--;
count++;
}
if (count==4)
{
cout<<"Sorry, you have exceeded 3 times of input."<<endl;
cout<<"Please restart the program or contact us for further services."<<endl;
exit(1);
}
}
for (i=1,i<=5,i++)
{
cout<<"Please insert the price of the product."<<endl;
cin>>price[i];
}
for (i=1,i<=5,i++)
{
cout<<"Please enter the quantity."<<endl;
cin>>quantity[i];
}
for (i=1,i<=5,i++)
if ((stocknumber[i]>=1) && (stocknumber[i]<=3000))
{
discount[i]=0;
}
else if ((stocknumber[i]>=3001) && (stocknumber[i]<=5000))
{
discount[i]=float(10)/100;
}
else if ((stocknumber[i]>=5001) && (stocknumber[i]<=8000))
{
discount[i]=float(15)/100;
}
else if ((stocknumber[i]>=8001) && (stocknumber[i]<=9999))
{
discount[i]=float(20)/100;
}
for (i=1,i<=5,i++)
{
pricetopay[i]=calpricetopay(quantity[i],price[i]);
discountprice[i]=caldiscountprice (discount[i],pricetopay[i]);
priceafterdiscount[i]=calpriceafterdiscount(pricetopay[i],discountprice[i]);
cout<<"Price to pay="<<pricetopay[i]<<endl;
cout<<"The price of the item after discount="<<priceafterdiscount[i]<<endl;
}
return 0;
}
float calpricetopay (int quantity[i], float price[i])
{
for (i=1,i<=5,i++)
{
float pricetopay[i];
pricetopay[i]=float(quantity[i])*price[i];
return pricetopay[i];
}
}
float caldiscountprice (float discount[i], float pricetopay[i])
{
float discountprice[i];
for (i=1,i<=5,i++)
{
discountprice[i]=discount[i]*pricetopay[i];
return discountprice[i];
}
}
float calpriceafterdiscount(float pricetopay[i], float discountprice[i])
{
float priceafterdiscount[i];
for (i=1,i<=5,i++)
{
priceafterdiscount[i]=pricetopay[i]-discountprice[i];
return priceafterdiscount[i];
}
}