Need so help with a code. Im stuck.

Im trying to figure out my errors in the following code. Any help or advice would be great.

***********************************************************************
*// Write a program to calculate the total weight of the rebar used **
*// The input specifications are these: **
*// Use a 2-D array named bar_data [20] [3] to read the ASTM **
*// standard reinforcing bars' size, weight, and diameter. **
*// Use a 2-D array named bar_used [10] [2] to read the bar used **
*// and length for the basement. **
*// **
***********************************************************************

#include <iostream>
using namespace std;
const int MAX_NUM_ROWS = 20, MAX_NUM_COLS = 20;

void function1 (int, int, int[ ] [MAX_NUM_COLS]);

int main()
{

double bar_data[20][3] = {{2, 0.167, 0.250}, {3, 0.376, 0.375}, {4, 0.668, 0.500}, {5, 1.043, 0.625},
{6, 1.502, 0.750}, {7, 2.044, 0.875}, {8, 2.670, 1.000}, {9, 3.400, 1.128},
{10, 4.303, 1.270},{11, 5.313, 1.410},{14, 7.650, 1.693},{18, 13.600, 2.257}};
double bar_used[10][2] = {{4, 5000}, {10, 2000} ,{14, 1200} ,{18, 900}};
int pos1, pos2, check, rPos;
double size, diameter, length, weight;
string str;

cout << "Size << Diameter(in) << Length(ft)<< Weight(lb)\n";
size = 0;
diameter = 0;
length = 0;
weight = 0;

for (int i = 0; i < 20; i++)
{
check = 0;
pos1 = bar_data[i][0];

for (int j = 0; j < 10; j++)
{
pos2 = bar_used[j][0];

if (pos1 == pos2)
{
check = 1;
rPos = j;
}
else
continue;
}

if ((check == 1) && (pos1 != 0))
{
cout << "\t" << pos1 << "\t" << bar_data[i][2] << "\t\t";
cout << bar_used[rPos][1] << "\t\t";
cout << (bar_data[i][1]*bar_used[rPos][1]) << "\n";
size = size + pos1;
diameter = diameter + bar_data[i][2];
length = length + bar_used[rPos][1];
weight = weight + (bar_data[i][1]*bar_used[rPos][1]);
}
else
{
continue;
}
}

cout << "Total\t" << size << "\t" << diameter << "\t\t" << length << "\t\t" << weight << endl;

system ("pause");
return 0;
}
What errors are you getting?
Shouldn't pos1 and pos2 be doubles?

PLEASE USE CODE TAGS (the <> formatting button) when posting code. It makes it easier to help you.
Last edited on
Anon,

Looking at my compiler errors on Dev-C++ it gives the following but im not quite understanding the missing part.



C:/Dev-Cpp/include/c++/3.4.2/mingw32/bits/c++config.h:57: error: expected unqualified-id before "namespace"

C:/Dev-Cpp/include/c++/3.4.2/mingw32/bits/c++config.h:57: error: expected constructor, destructor, or type conversion before "namespace"

C:/Dev-Cpp/include/c++/3.4.2/mingw32/bits/c++config.h:57: error: expected `,' or `;' before "namespace"

C:/Dev-Cpp/include/c++/3.4.2/mingw32/bits/c++config.h:61: error: expected namespace-name before ';' token

C:/Dev-Cpp/include/c++/3.4.2/mingw32/bits/c++config.h:61: error: `<type error>' is not a namespace

C:\Users\Dave\Documents\Strayer Homework\CIS 326\week 3 program application 1.cpp: In function `int main()':

C:\Users\Dave\Documents\Strayer Homework\CIS 326\week 3 program application 1.cpp:37: warning: converting to `int' from `double'

C:\Users\Dave\Documents\Strayer Homework\CIS 326\week 3 program application 1.cpp:41: warning: converting to `int' from `double'

Execution terminated
Did you include the comments in front of the #include <iostream>? Those are not legal C++ comments and would confuse the compiler when it tries to read <iostream> which presumably includes the Dev-C++ specific config.h header.

The last two warnings are from your assigning a double to an int, which I pointed out in my earlier response.
Anon,

Thanks for the heads up. Ive placed comments in my codes before and never had a problem. But that cleared it all up. As for the double and int, should i be using int instead of double?
the program compiles and runs like it should even with the warnings. The only thing i could do would be lining up the rows so the centered. Thanks again for your help. This isn't easy while deployed.
Topic archived. No new replies allowed.