0% found this document useful (0 votes)
63 views7 pages

Homework: 1.A 1.A Source Code:: "Dancarlix Perez" Homework "1" Page 1 of 7

The document contains source code for three C programming assignments: 1) A sales commission calculator that uses a while loop to repeatedly calculate and print a salesperson's salary based on their sales. 2) An interest calculator that uses a while loop to repeatedly calculate and print the simple interest for a loan based on input values for principal, interest rate, and term. 3) A program that uses nested while loops to print hollow squares of varying sizes based on user input for the side length. The program runs three times to print three squares.

Uploaded by

Dan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views7 pages

Homework: 1.A 1.A Source Code:: "Dancarlix Perez" Homework "1" Page 1 of 7

The document contains source code for three C programming assignments: 1) A sales commission calculator that uses a while loop to repeatedly calculate and print a salesperson's salary based on their sales. 2) An interest calculator that uses a while loop to repeatedly calculate and print the simple interest for a loan based on input values for principal, interest rate, and term. 3) A program that uses nested while loops to print hollow squares of varying sizes based on user input for the side length. The program runs three times to print three squares.

Uploaded by

Dan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

“Dancarlix Perez” Homework “1” Page 1 of 7

Homework: 1.A -
1.A Source Code:
//Homework 1A: Problem #3.18

//Sales Commission Calculator

//Desire output: Determine the salary of salesperson in a company

//Prewriting Steps:
//Calculate salary
//Print salary
//Repeat loop until condition fails

//Drafting Steps:
//1.Declare variables
//2.Prompt user to enter sales
//3.Use "While" statement to calculate salary
//While sales is not equal to -1. System will continue to accept input until -1 is entered.
//4.Input sales
//5.Output to screen

#include <stdio.h> //Header file//

int main(void) //Program function//


{
float sales, salary; //Local variable declaration//

printf("Enter Sales in dollars (-1 to end): "); //Output to screen prompts user to enter sales. -1 will end program//
scanf("%f", &sales); //Scanner reads sales to verify validity of condition//

while (sales !=-1) //While loop is executed until the condition becomes false, in this case entering -1//
{

salary = 200 + ((sales*9)/100); //Salary calculation based on input above including the extra 9%//
printf("\nSalary is $%.2f", salary); //Salary is displayed up to 2 decimal places//
printf("\nEnter Sales in dollars (-1 to end): "); //While loop executed until user enters -1//
scanf("%f", &sales); //Scanner reads sales to verify the validity of condition. Loop ends if condition is -1//
}

return 0; //Exit main function


}

1A Program Output:
“Dancarlix Perez” Homework “1” Page 2 of 7

Homework: 1.B -
1.B Source Code:
//Homework 1B: Problem #3.19

//Interest Calculator

//Desire output: Determine the simple interest on a loan.

//Prewriting Steps:
//Calculate interest
//Print simple interest for loan entered
//Repeat loop until condition fails

//Drafting Steps:
//1.Declare variables
//2.Prompt user to enter values for variables
//3.Use "While" statement to calculate interest rate
//While loop runs and applies values. System will continue to accept values until loop is finished by -1 at the start of a loop.
//4.Determine the operation to calculate the interest rate
//Use given formula
//5.Output to screen

#include <stdio.h> //Header file//

int main(void) //Program function//


{
float principal, interestRate, interest; //Local variable declaration//
int days; //"days" are defined as integers//
“Dancarlix Perez” Homework “1” Page 3 of 7

printf("Enter loan principal (-1 to end): "); //Output to screen prompts user to enter loan principal. -1 will end program//
//Note: At this stage program will run if value entered is not -1//

scanf("%f", &principal); //Scanner reads principal to verify validity of condition//

while (principal !=-1) //While loop is executed. At this stage entering -1 will not make the statement false, program will
continue to run//
{

printf( "\nEnter interest rate: "); //Output to screen prompts user to enter interest rate//
scanf( "%f", &interestRate); //Scanner reads input for interest rate//

printf( "\nEnter term of the loan in days: "); //Output to screen prompts user to enter the number of days for the loan//
scanf( "%d", &days); //Scanner reads input for number of days//

interest = (principal * interestRate * days)/365; //Interest calculation based on the values entered for the variables above//
printf("\nThe interest charge is $%.2f",interest); //Interest charge is displayed up to 2 decimal places//

printf("\nEnter loan principal(-1 to end): "); //While loop executed until user enters -1//
scanf("%f", &principal); //Scanner reads sales to verify the validity of condition. Loop ends if condition is -1//
}

return 0; //Exit main function//


}

1.B Program Output:


“Dancarlix Perez” Homework “1” Page 4 of 7

Homework: 1.C -
1.C Source Code:
//Homework 1C: Problem #3.33

//Hollow Square of Asterisks

//Desire output: Print a hollow square made of asterisks.

//Prewriting Steps:
//Determine square size
//Code pattern. While and nest while loop
//Repeat loop until condition fails

//Drafting Steps:
//1.Declare variables
//2.Prompt user to enter the length of each side of the square
//3.Use "While" statements to build each side until square is formed
//While loop runs and applies values.
//4.Repeat process 3 times within the main function to print 3 different size squares
//5.Output to screen

#include <stdio.h> //Header file//

int main(void) //Program function//


{
int side, row, col; //Local variable declaration//

printf("\nEnter the side of the square: \n"); //Output to screen prompts user to enter loan principal. -1 will end
program//

scanf("%d", &side); //Scanner reads input of printf to verify validity of condition//


row = side; //Define variable row and col as sides
col = side;

while (row > 0) //While loop is executed//


{
while (col > 0) //Nested while loop to complete each side of the square
{

if (row == 1)
{
printf("*");
}
else if (row == side)
{
printf("*");
“Dancarlix Perez” Homework “1” Page 5 of 7

}
else if (col == 1)
{
printf("*");
}
else if (col == side)
{
printf("*");
}
else
printf(" ");
col--;
} //By this input, asterisks will print to build the 1st row, last row, and sides

printf("\n");
row--;
col = side;
}

//Program repeated to complete 3 runs on assignment

printf("\nEnter the side of the square: \n"); //Output to screen prompts user to enter loan principal. -1 will end
program//

scanf("%d", &side); //Scanner reads input of printf to verify validity of condition//


row = side;
col = side;

while (row > 0) //While loop is executed//


{

while (col > 0)


{

if (row == 1)
{
printf("*");
}
else if (row == side)
{
printf("*");
}
else if (col == 1)
{
printf("*");
}
else if (col == side)
{
“Dancarlix Perez” Homework “1” Page 6 of 7

printf("*");
}
else
printf(" ");
col--;
}

printf("\n");
row--;
col = side;
}

//Program repeated to complete 3 runs on assignment//

printf("\nEnter the side of the square: \n"); //Output to screen prompts user to enter loan principal. -1 will end
program//

scanf("%d", &side); //Scanner reads input of printf to verify validity of condition//


row = side;
col = side;

while (row > 0) //While loop is executed//


{

while (col > 0)


{

if (row == 1)
{
printf("*");
}
else if (row == side)
{
printf("*");
}
else if (col == 1)
{
printf("*");
}
else if (col == side)
{
printf("*");
}
else
printf(" ");
col--;
}
“Dancarlix Perez” Homework “1” Page 7 of 7

printf("\n");
row--;
col = side;
}

return 0; //Exit main function//


}
1.C Program Output:

You might also like