#include <iostream>
#include <string>
usingnamespace std;
int main()//use int main
{
int num_receipts;
string salesman1, salesman2;//STRING NOT INT
int salesman1_total = 0, salesman2_total = 0;
int price, cost;
int initial_stock_on_hand;
cout << "Name of salesman #1? "; //this sais name so i changed it to string..
cin>>salesman1;
cout << "Name of salesman #2? ";//same as above
cin>>salesman2;
cout << "What's the initial stock on hand? ";//fine
cin>>initial_stock_on_hand;
cout << "What's the sales price for a computer? ";//perfect
cin>>price;
cout << "What's your cost per unit? ";//couldnt be better
cin>>cost;
cout << "How many sales receipts are there? ";//fantastic
cin>>num_receipts;
for(int i=1; i<=num_receipts; i++)
{
int quantity;
int salesman_id;
cout<<"Data for sales receipt #"<<i<<endl;
cout<<"Who was the salesman?: ";
cin>>salesman_id;
cout<<"How many computers?: ";
cin>>quantity;
if(salesman_id==1)
salesman1_total+=quantity;
elseif(salesman_id==2)
salesman2_total+=quantity;
}
int total_quantity=salesman1_total+salesman2_total;
cout<<"---------End of the day report---------"<<endl;
cout<<"Initial stock at hand: "<<initial_stock_on_hand<<endl;
cout<<"Total quantity sold: "<<total_quantity<<endl;
cout<<"Day's take: "<<total_quantity*price<<endl;
cout<<"Day's profit: "<<total_quantity*(price-cost)<<endl;
if(salesman1_total>salesman2_total)
cout<<"Winnder is "<<salesman1<<" with "<<salesman1_total<<" sales."<<endl;
elseif(salesman2_total>salesman1_total)
cout<<"Winnder is "<<salesman2<<" with "<<salesman2_total<<" sales."<<endl;
else
cout<<"Sales man 1 and two are equal!";
cin.ignore();
cin.ignore();
cin.ignore();
return 0;
}
THIS Works fine, your code was a bit messy so i rewrote it.
The first problem is that you are asking for a name to be typed in yet the variable type is an integer! Unless you are an alien where you guys call yourself 25213 you need to change that to a string;
The second problem which can cause unforseen errors is that you just declared main and not int main() I dont know the exact details of this one but i remember reading an article that sais its a no no. so unless you know what youre doing i would refrain from doing that.
anyways you might want to add in a system("Pause")(EDIT:Though most people will tell you not to use that in "real" applications) in there because cin.ignore() sucks (it gets stuck in an input buffer and so you never know when you need to put like 5 of them in there);
if this were a real application id probably ask you to redo it however. There are some very confusing parts in it like the sales man id. why not just use their names? And a few other things that i had to think about for some time before i understood.