Help finding largest number in loop

I usually don't post like this but I'm new to C and I've been stuck on this for so long its frustrating. The program needs to be able to loop and calculate the expected time for more than one project and I can't figure out why it wont display which project number had the longest expected time. Lines 52-62 are what i've tried but I can't quite figure it out. It keeps printing that the most recent project calculated is the one with the longest expected time.

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
#include <stdio.h>


int main( void )
{
	unsigned int counter;
	int projectnumber;
	int optimistictime;
	int realistictime;
	int pessimistictime;
	int longesttime;
	int longestproject;
	int ask;

	float expectedtime;

	counter = 0;
	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); 
	longestproject = 0;
	longesttime = 0;

	while ( ask > 0 ) {

	printf( "%s", "Enter Project Number: " ); 
	scanf( "%d", &projectnumber); 

	
		printf( "%s", "Enter Optimistic Time(in weeks): " ); 
	scanf( "%d", &optimistictime); 

	printf( "%s", "Enter Realistic Time(in weeks): " ); 
	scanf( "%d", &realistictime); 

	printf( "%s", "Enter Pessimistic Time(in weeks): " ); 
	scanf( "%d", &pessimistictime); 


      counter = counter + 1; // increment counter
	//calculate and display information
	  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);

	expectedtime = (float) (optimistictime + 4*realistictime + pessimistictime)/6;

	printf("The Expected Time is %.1f\n", expectedtime);

		if (expectedtime > longesttime)
	{ 
		expectedtime = longesttime;
		longestproject = projectnumber;
	}
	else {
		
	}
      
  	printf( "%s", "Would you like to calculate the expected time for an Activity?\n1 for yes, -1 for no: ");
	scanf( "%d", &ask);

	
       
   } // end while

	while (ask < 0 ) {

	printf("The Number of Records Processed is: %d\n", counter ); 
	printf("The Project Number with the Longest Expected time is: %d\n", longestproject); 
	system("PAUSE");
	return 0;


	}

}
Last edited on
the assignment on the line 56 is the problem - you want the longesttime to equal to expectedtime, not reversely...
if think this is right longesttime = expectedtime;
I don't know why I didn't realize that, thanks for the help.
Topic archived. No new replies allowed.