C++ Function help

The goal of the program is to get the different time estimates for an activity and
then to calculate the expected time and display the longest activity calculated. I have not finished the last part of the program yet because I can not figure out why the function where im getting the inputs is not returning the values. So whenever I run the program the project number, optimistic time, and everything else just shows up as 0 and i cant figure out why. This is for homework and I'm pretty lost on this.

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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <stdio.h>


//function prototypes
void inputData(int* projectnumber, float* optimistictime, float* realistictime, float* pessimistictime);
void processingData(float projectnumber, float optimistictime, float realistictime, float pessimistictime, float expectedtime, float longesttime, float longestproject);
void outputInfo(float optimistictime, float realistictime, float pessimistictime, float expectedtime, float projectnumber);
void outputFinal(float longesttime, float longestproject);

int main( void )
{
	unsigned int counter;

	int ask;
	int projectnumber;
	float optimistictime;
	float realistictime;
	float pessimistictime;
	float longesttime;
	float expectedtime;
	float longestproject;

	counter = 0;
	longesttime = 0;
	longestproject = 1;
	expectedtime = 0;
	

	//getfirstproject
	printf( "%s", "Would you like to calculate the expected time for an Activity?\n1 for yes, -1 for no: ");
	scanf( "%d", &ask); 

	
	//start loop
	while ( ask > 0 ) 
	{
	counter = counter + 1; //count number of projects
	inputData(&projectnumber, &optimistictime, &realistictime, &pessimistictime); // call 
	processingData(projectnumber, optimistictime, realistictime, pessimistictime, expectedtime, longesttime, longestproject); //call
	outputInfo(optimistictime, realistictime, pessimistictime, expectedtime, projectnumber);

	printf( "%s", "Would you like to calculate the expected time for an Activity?\n1 for yes, -1 for no: ");
	scanf( "%d", &ask);

	}

}




void inputData(int* projectnumber, float* optimistictime, float* realistictime, float* pessimistictime)
{
    printf("Enter the Project Number: "); // ask user to input the product number
    scanf("%d", projectnumber);
    while (*projectnumber < 1 || *projectnumber > 100)
	{
          printf("Invalid Project number - it must be in the range of 1 to 100:");
		  scanf("%d", projectnumber);
	}


     printf("Enter the Optimistic Time: "); // ask user to input optimistic time
     scanf("%d", optimistictime);
     while (*optimistictime < 0 || *optimistictime > 10) // while loop to check if valid response 
    {
         printf("Invalid time, time must be between 0 and 10 weeks.:");
         scanf("%d", optimistictime);
    }
        

     printf("Enter the Realistic Time: "); // ask user to input realistic time
     scanf("%d", realistictime);
     while (*realistictime < 0 || *realistictime > 10) // while loop to check if valid response 
    {
         printf("Invalid time, time must be between 0 and 10 weeks.:");
         scanf("%d", realistictime);
    }


	 printf("Enter the Pessimistic Time: "); // ask user to input pessimistic time
     scanf("%d", pessimistictime);
     while (*pessimistictime < 0 || *pessimistictime > 10) // while loop to check if valid response 
    {
         printf("Invalid time, time must be between 0 and 10 weeks.:");
         scanf("%d", pessimistictime);
    }
       
    return;
}

void processingData(float projectnumber, float optimistictime, float realistictime, float pessimistictime, float expectedtime, float longesttime, float longestproject) //Process data
{
	expectedtime = (float) (optimistictime + 4*realistictime + pessimistictime)/6; //calculate expected time
			if (expectedtime > longesttime)
	{ 
		longesttime = expectedtime; //calculate if project is longest project
		longestproject = projectnumber;
	}
	else {
		
	}



	return;
}

void outputInfo(float optimistictime, float realistictime, float pessimistictime, float expectedtime, float projectnumber) //print results
{ 
	printf("The Project Number is %d\n", projectnumber);
	 printf("The Optimistic Time is %d\n", optimistictime);
	printf("The Realistic Time is %d\n", realistictime);
	printf("The Pessimistic Time is %d\n", pessimistictime);
	printf("The Expected Time is %.1f\n", expectedtime);
	return;
}
Last edited on
Topic archived. No new replies allowed.