I have to do this:
Information on the sale and purchase of a company will be saved in a data structure.
Struct consists of the name of the shopping company, the shopping type (buy or sell),
the amount of shopping, date of shopping and shopping description (like discount).
1. Define the data structure to keep the information about 1000 companies.
2. This data structure was assumed that the necessary information has been entered in
advance, please write the function that calculate how much the sale and purchase of the
company are. (do not write main() function…)
and I have this code but it do not work. What is/are the problem/s?
#include <iostream>
#include <cstring>
#include <conio.h>
#define n_shop 1000
struct Date
{
int day;
int month;
int year;
};
struct Company
{
char shop[50];
char bos;
float amount;
Date d_shopping;
int disc;
}name[n_shop];
float calculate (company total)
{
int h=0;
int i;
for (i=0; i<n_shop; i++)
{
if(name[i].BoS=='b')
total=total - name[i].amount + (name[i].amount*(name[i].discount/100));
if(name[i].BoS=='s')
total=total + name[i].amount - (name[i].amount*(name[i].discount/100));
// Where is main?
#include <iostream> // why do you need this?
#include <cstring> // why do you need this?
#include <conio.h> // why do you need this?
#define n_shop 1000
struct Date
{
int day;
int month;
int year;
};
struct Company
{
char shop[50];
char bos;
float amount;
Date d_shopping;
int disc;
}name[n_shop];
float calculate (company total) // Is it "C"ompany?
{
int h=0;
int i;
for (i=0; i<n_shop; i++)
{
if(name[i].BoS=='b')
// when did you initialize elements of array 'name'? Is there any probability you call this function before initialization?
// is "BoS" is supposed to be bos?
total=total - name[i].amount + (name[i].amount*(name[i].discount/100));
// where did you declared variable 'total'?
// Is Company structure is supposed to have member variable 'discount'? Isn't it disc?
if(name[i].BoS=='s')
total=total + name[i].amount - (name[i].amount*(name[i].discount/100));
}
return (total); // Why does it needs to be sealed with parenthesis?
}