Create a source code that will prompt for recive and total a collection of payroll amounts entered at the terminal untill a sentinel amount of 999 is entered. Here is what i have so far i know not much but am not that great at this class.
#include <stdio.h>
#include <stdlib.h>
main()
{
int total payroll amounts;
float 0;
printf("Enter a number(999 to stop)");
scanf("%d" , &num);
//*putting the first number the user entered
while(num=999)
{
Here is an updated version of your code with the necessary changes:
```c
#include <stdio.h>
int main() {
float num, total = 0;
printf("Enter a number (999 to stop): ");
scanf("%f", &num);
// Collect and sum up payroll amounts until 999 is entered
while (num != 999) {
total += num;
printf("Enter a number (999 to stop): ");
scanf("%f", &num);
}
printf("Total payroll amount: %.2f\n", total);
return 0;
}
```
Explanation:
1. We start by declaring the `total` variable which will store the sum of the payroll amounts.
2. Inside the `while` loop, we prompt the user to enter a number using `printf` and then collect the input using `scanf` and store it in the `num` variable.
3. We check if the value of `num` is equal to 999 using the `!=` operator. If it is not equal to 999, the loop will continue executing.
4. Inside the loop, we add the value of `num` to the `total` variable using the `+=` operator.
5. After each iteration, we again prompt the user to enter a number and collect the input in the `num` variable.
6. When the user enters 999, the condition `num != 999` becomes false, and the loop stops executing.
7. Finally, we print the total payroll amount using `printf` and display it with two decimal places using `%.2f`.
Make sure to save the code in a `.c` file and compile and run it to see the results.