Need help

Hi,guys! I am working on my project but when I run it, it does not follow my instruction, can you help me to check what is wrong with my code please? It is not finished yet, but I cannot finish it without figure out what is wrong.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
	
	double 	NH, NB, NS, NT, VH, VB, VS, VT,VHS,VBS,VSS, i, VC, PH, PB, PS, profit, PI, per_H, per_B, per_S,order_H,order_B,order_S,first,second,third;
	PI=3.1415926;
	ifstream infile;
	infile.open("Batch_03.txt");
	i=0;
	while (infile>>NH>>NB>>NS)
	{
        i++;
        NT=NH+NB+NS;
		PH=NH/NT;
		PB=NB/NT;
		PS=NS/NT;
		if (PH>=0.1&&PB>=0.1&&PS>=0.1)
		{
			VHS=PI*10*10*10/(12*12*12);
			VBS=8*10*18/(12*12*12);
			VSS=7*7*12/(12*12*12);
			VH=NH*VHS;
		    VB=NB*VBS;
		    VS=NS*VSS;
		    VT=(VH+VB+VS)*1.12;
		    VC=10*11*12;
			if (VT<=VC)
			{
				per_H=2.75/VHS;
			    per_B=3.19/VBS;
				per_S=1.07/VSS;
		    	if (per_H<per_B&&per_H<per_S&&per_B>per_S)
				{
					order_H=third;
					order_S=second;
					order_B=first;
				}
				if (per_H<per_B&&per_H<per_S&&per_B<per_S)
				{
					order_H=third;
					order_B=second;
					order_S=first;
				}
				if (per_H<per_B&&per_H>per_S)
				{
					order_S=third;
					order_H=second;
					order_B=first;
				}
				if (per_H>per_B&&per_H>per_S&&per_B>per_S)
				{
					order_S=third;
					order_B=second;
					order_H=first;
				}
				if (per_H>per_B&&per_H<per_S)
				{
					order_B=third;
					order_H=second;
					order_S=first;
				}
				if (per_H>per_B&&per_H>per_S&&per_S>per_B)
				{
					order_B=third;
					order_S=second;
					order_H=first;
				}
					cout<<"The order of giving away of hat is "<<order_H<<" The order of giving away of boots is "<<order_B<<" The order of giving away of shillelaghs is "<<order_S;
			}
			else
			{
				cout<<"Batch "<<i<<"works"<<endl;
			    profit=2.75*NH+3.19*NB+1.07*NS;
			    cout<<"the profit is "<<profit<<endl;
			}
			
		}
		else
		{
			cout<<"not enough amount"<<endl;
		}
	}
	system ("pause");
	return 0;
}.
I have no clue what your program is supposed to do, so I can't tell you what might be wrong.

Your variable names are useless to yield any understanding.
Your total lack of comments also does not provide any insight in what the program is supposed to do.
As AbstractionAnon stated, the variable names are not descriptive and I have no idea what each variable is supposed to store.

You could include a comment line to describe the purpose of each variable or simply make the variable identifier descriptive

PI can be a constant like this since we both know PI value will not change
 
const double PI = 3.1415926;


Looks like i variable can be declared as int, not double since it is used to identify batch number, which is always an integer, right?
 
int i = 0;


 
system ("pause");

what is this doing at the end of your program? I think that line can go away.


Definitely include the purpose of this program, what it needs to do, what input and output will be like, and maybe some examples so we may assist you better.
Last edited on
Topic archived. No new replies allowed.