Please Help me with my C++ code :)

I very new to C++ and am almost done with a project I am working on but I just have two bugs that need to be corrected there is some kind of error in the break and sum, and I cant figure out how to correct them. Please Help!
I am working on a program to compute the percent of the batches rejected due to pressure, due to temperature and the percent rejected due to dwell time.
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include<cmath>
using namespace std;

int main()
{
ifstream input;
ofstream output;

double fail, count, tempfail, pressfail, sumbatch, temperature, pressure, dwell, batch;
string filename;
ifstream suture;
ofstream report;

cout << "Enter the name of input file ";
cin >> filename;
input.open("suture.dat");


if( input.fail())

{
if(temperature == -99 || dwell == -99);
break;
cerr << "Error when opening input file\n" << filename << endl;
return(1);
}

input >> batch >> temperature >> pressure >> dwell;


{
for(batch >= 24551; temperature < 150; temperature >170)
{


{
++count;
sum = tempfail;
}
}
for(batch >= 24551; pressure < 60; pressure > 70);
{

{
++count;
sum = pressfail;
}
}
for(batch >= 24551; dwell < 2; dwell < 2.5);
{
++count;
sum = dwellfail;
}
cout << "Total number of temperature fails is "<< tempfail/5*100 <<" percent"<< endl;
cout << "Total number of pressure fails is "<< pressfail/5*100 <<" percent"<< endl;
cout << "Total number of dwell fails is "<< dwellfail/5*100 <<" percent"<< endl;
}
system("PAUSE");
return 0;
}
What bugs?
Please edit your post to use code tags (the <> formatting button). It makes it easier to read your code and also makes it easier to respond to your post.
[code]
code here
[/code]


Sorry for not using tags!

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
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include<cmath>
using namespace std;

int main()
{
ifstream input;
ofstream output;

double fail, count, tempfail, pressfail, sumbatch, temperature, pressure, dwell, batch;
string filename;
ifstream suture;
ofstream report;

cout << "Enter the name of input file ";
cin >> filename;
input.open("suture.dat");


if( input.fail())

{
if(temperature == -99 || dwell == -99);
break;
cerr << "Error when opening input file\n" << filename << endl;
return(1);
}

input >> batch >> temperature >> pressure >> dwell;


{
for(batch >= 24551; temperature < 150; temperature >170)
{


{
++count;
sum = tempfail;
}
}
for(batch >= 24551; pressure < 60; pressure > 70);
{

{
++count;
sum = pressfail;
}
}
for(batch >= 24551; dwell < 2; dwell < 2.5);
{
++count;
sum = dwellfail;
}
cout << "Total number of temperature fails is "<< tempfail/5*100 <<" percent"<< endl;
cout << "Total number of pressure fails is "<< pressfail/5*100 <<" percent"<< endl;
cout << "Total number of dwell fails is "<< dwellfail/5*100 <<" percent"<< endl;
}
system("PAUSE");
return 0;
}
http://www.cplusplus.com/doc/tutorial/control/


Have a read of that - will show you how to do a for loop.

There should have been compiler errors - if you still have them after fixing the for loops, then post them in full.

Also can you indent your code properly?
Well I'm unable to compile and command prompt is telling me the sum was not declared in this scope, also that the break statement is not within loop, and its says my "dwellfail" inst declared. However I am not sure how to correct these problems. Thanks!!
TheIdeasMan wrote:

if you still have them after fixing the for loops, then post them in full.


Have you fixed the for loops?

When you have compile errors - you should be able to copy them to the clipboard - then you can paste them here in full.

Have you thought about using an IDE (Integrated Development Environment)? Compiling from the cmd line is good to know, but it can be a very hard road for beginners. There are lots of free IDE's for various operating systems.
Thanks for the help with the loops! I was able to get the program to compile, however when I'm in the program (the .exe) and type in the .dat file i want, I don't receive any output from the program

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
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include<cmath>
using namespace std;

int main()
{
	ifstream input;
	ofstream output;

	double sum, fail, count, dwellfail, tempfail, pressfail, sumbatch, temperature, pressure, dwell, batch; 
	string filename;
	ifstream suture;
	ofstream report;
	
	cout << "Enter the name of input file "; 
	cin >> filename;
	input.open("suture.dat"); 
	
	
	if( input.fail())
	
	{
		if(temperature == -99 || dwell == -99);
		
		cerr << "Error when opening input file\n" << filename << endl;
			return(1); 
	}
	
	input >> batch >> temperature >> pressure >> dwell;
	
	
	{
		for(batch >= 24551; temperature < 150; temperature >170)
		{		
			
	
			{
			++count;
			sum = tempfail;
			}	
		}	
		for(batch >= 24551; pressure < 60; pressure > 70);
		{
			
			{
			++count;
			sum = pressfail;
			}
		}	
		for(batch >= 24551; dwell < 2; dwell < 2.5);
		{
			++count;
			sum = dwellfail;
		}	
		cout << "Total number of temperature rejections "<< tempfail/5*100 <<" percent"<< endl;
		cout << "Total number of pressure rejections "<< pressfail/5*100 <<" percent"<< endl;
		cout << "Total number of dwells rejections "<< dwellfail/5*100 <<" percent"<< endl;
	}
	system("PAUSE");
return 0;
}



Dat File

1
2
3
4
5
6
7
8
9

Batch Number    Temperature      Pressure            Dwell Time

24551                145.5                62.3                2.23
24582                153.7                62.3                2.52
26553                160.3                62.3                2.51
26623                159.5                62.3                2.01
26642                160.3                62.3                1.98
-99                     -99                   -99                     -99
Line 22: Shouldn't you be opening filename ?
Line 28: Why is it there? The ; after the if causes it not to do anything.

You only read a single line of input at line 34. That's going to fail if you input file has the blank lines and columns headers shown in the Dat file you posted.

Thanks for the help! Correcting those issues made my program work! :)
Thanks again!
Topic archived. No new replies allowed.