Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*=======================================================
- Programmer: Blake Gifford
- Email: bgifford@purdue.edu
- CNIT 105, InLab03
- Lab Session Time: Tuesday @9:30
- Program Description: Partially fill an array with up to 20 students’ GPAs by prompting the user in a loop.
- ==========================================================*/
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- #include <stdlib.h>
- #define SIZE 20
- //ONE
- int main()
- {
- float students[SIZE];
- float students2[SIZE];
- float gpa;
- int ctr;
- int ctr2 = 0;
- float num;
- float average;
- float sum = 0;
- float max;
- printf("Assignment06 - Output");
- printf("\n=======================\n\n");
- //TWO
- for (ctr = 0; ctr < SIZE; ctr++)
- {
- printf("Enter a GPA, -1 to stop the data entry: ");
- scanf("%f", &num);
- if (num == -1)
- {
- ctr2 = ctr;
- break;
- }
- students[ctr] = num;
- //average
- sum = sum + students[ctr];
- average = sum / (ctr + 1);
- max = students[0];
- //plus .2
- if (num + 0.2 >= 4.00)
- {
- students2[ctr] = 4.00;
- max = 4.00;
- }
- else if (num + 0.2 < 4.00)
- {
- students2[ctr] = num + 0.2;
- }
- }
- //THREE
- printf("\n\nNumber of GPA's entered = %d", ctr);
- //FOUR UNSURE OF THE PRINT
- printf("\n\nContents of the array:\n======================");
- for (ctr = 0; ctr < ctr2; ctr++)
- {
- printf("\n %.2f", students[ctr]);
- }
- //FIVE AVERAGE
- printf("\n\nAverage GPA = %.2f", average);
- //SIX ADD .2 TO ALL GPA
- printf("\n\nUpdated Array:\n=================");
- for (ctr = 0; ctr < ctr2; ctr++)
- {
- printf("\n %.2f", students2[ctr]);
- }
- for (ctr = 0; ctr < ctr2; ctr++)
- {
- if (students[ctr] > max)
- {
- max = students[ctr];
- }
- else if (students[ctr] <= max)
- {
- max = max;
- }
- }
- printf("\n\nMaximum GPA = %.2f", max);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement