#include <iostream>
#include <cmath>
using namespace std;
typedef string ActType[50];
int main () {
ActType act;
int numOfact;
int ET;
cout<<"Enter the number of activity to be read: ";
cin>>numOfact;
for (int a = 0; a < numOfact; a++){
cout<<"Enter Activity: ";
cin>>a[act];
}
for (int ip = 0; ip < numOfact; ip++){
cout<<"Enter IP of "<<act[ip]<<": ";
cin>>ip[act];
}
for (int ot = 0; ot < numOfact; ot++){
cout<<"Enter OT: ";
cin>>ot;
Your variables OT, MT & PT exist only inside the for loops. They are declared in the declaration portion and will only be valid between those curly braces.
Try assigning them whilst inside the for loop to a variable declared outside the loop, i.e.
1 2 3 4 5 6 7
int pt_real = 0;
for (int pt = 0; pt < numOfact; pt++)
{
cout << "Enter PT:";
cin >> pt;
pt_real = pt; // assign pt_real the value of pt since pt will only exist inside this loop
}
just a suggestion, i don't know if it is a valid solution but its worth a shot.
I did and the suggestion I made will allow your program to run.
Here is the code I compiled. The variables you had originally used in your ET formula were variables that were only available to the for loops in which they were declared.
#include <iostream>
#include <cmath>
usingnamespace std;
typedef string ActType[50];
int main () {
ActType act;
int numOfact;
int ET;
int ot_r = 0;
int mt_r = 0;
int pt_r = 0;
cout<<"Enter the number of activity to be read: ";
cin>>numOfact;
for (int a = 0; a < numOfact; a++){
cout<<"Enter Activity: ";
cin>>a[act];
}
for (int ip = 0; ip < numOfact; ip++){
cout<<"Enter IP of "<<act[ip]<<": ";
cin>>ip[act];
}
for (int ot = 0; ot < numOfact; ot++){
cout<<"Enter OT: ";
cin>>ot;
ot_r = ot;
}
for (int mt = 0; mt < numOfact; mt++){
cout<<"Enter MT: ";
cin>>mt;
mt_r = mt;
}
for (int pt = 0; pt < numOfact; pt++){
cout<<"Enter PT: ";
cin>>pt;
pt_r = pt;
}
ET = (ot_r + 4 * mt_r + pt_r) / 6; // <------------ here is the only error :|
cout<<ET;
return 0;
}
when I entered 13 in the activity, OT became infinite loop and I cannot input on mt and pt. when I input 5 on the activity OT MT and PT only have two arrays. do get what I mean? o_0
This program is some kind of a table. "Activity IP OT MT PT ET " <<---- one column so I need to have solution of OT MT and PT so that I could output the answer to the ET.
Wait if you are trying to make a table why are you not using arrays? Wouldn't that make more sense? An array will allow you to establish rows & columns.
int pt_array[size]
for (int pt = 0; pt < numOfact; pt++)
{
cout<<"Enter PT: ";
cin>>pt_array[pt];
pt_r += pt_array[pt]; // add the value of the current index to the total of pt_r
}
This is the table I was referring because this is a PERT.cpp program actually
ACTIVITY IP OT MT PT ET ES EF LS LF Slack
A none 2 3 4 3 0 3 0 3 0
B
C
D
E
F
G
H
I
J
K
L
M
the code is the one I was doing and the output on the compiler must be this..
Enter the number of activity to be read: 13
Enter Activity: A
|
|
|
|
|
|
|
|
|
Enter Activity: M <--- 13th time
Enter IP of A: none
|
|
|
|
|
|
|
|
Enter IP of M: l <--- 13th time
Enter OT: 2
|
|
|
|
|
|
|
|
|
Enter OT: 2 <--- 13th time
Enter MT: 3
|
|
|
|
|
|
|
Enter MT: 2 <--- 13th time
Enter PT: 4
|
|
|
Enter PT: 2 <--- 13th time
ET of A is 3
ET of B is 12
|
|
|
|
|
ET of M is 2 <--- 13th time
to come up of that answer in the 1st column ET = (OT + 4 * MT + PT) / 6, just ignore the rest.
I really don't get this :|
I'm sorry I don't really understand what you're problem is, maybe a more informed member or someone who comprehends your issue can offer you help. I tried, remain patient, more people will respond.
#include <iostream>
#include <cmath>
usingnamespace std;
typedef string ActType[50];
int main () {
ActType act;
int numOfact;
int eT;
int ot1, mt1, pt1;
cout<<"Enter the number of activity to be read: ";
cin>>numOfact;
for (int a = 0; a < numOfact; a++){
cout<<"Enter Activity: ";
cin>>a[act];
}
for (int ip = 0; ip < numOfact; ip++){
cout<<"Enter IP of "<<act[ip]<<": ";
cin>>ip[act];
}
for (int ot = 0; ot < numOfact; ot++){
cout<<"Enter OT: ";
cin>>ot1;
}
for (int mt = 0; mt < numOfact; mt++){
cout<<"Enter MT: ";
cin>>mt1;
}
for (int pt = 0; pt < numOfact; pt++){
cout<<"Enter PT: ";
cin>>pt1;
}
eT = (ot1 + 4 * mt1 + pt1) / 6; // <------------ here is the only error :|
cout<<eT;
system("PAUSE");
return 0;
}