Commit 60cb3fc4 by remirz

Upload New File

parent 8aa1af5f
Showing with 129 additions and 0 deletions
#include <stdio.h>
#include <string.h>
float NewPrice(float x, float y, int z, int k);
//declaring a function NewPrice type float
void Manufacturer(char company[]);
//declaring a function Manufacturer type void
void Input(int size, char company[size][15], float price[size]);
//declaring a function Input type void
float Discount();
//declaring a function Discount type float
int main(){
int i, size = 0;
//declaring variables i and size type integer
float discount = 61;
//declaring variable discount which is equals 61 type integer
do{
puts("Input number of the companies (not less than 1 and not more than 15)");
scanf("%d", &size);
}while(size < 1 || size > 15);
//do while loop
//program will start this loop because value of size is in the range of while statement
//program print text and user will input a value of size until size will not be in the range
char company[size][15];
//declaring 2D array company type char
float price[size];
//declaring array price type float
Input(size, company, price);
discount = Discount();
//these lines are working like a links to the functions
puts("\nOld price");
puts("\nManufacturer\tPrice");
//program just print Old price then Manufacturer on next line an Price in next coloumn
for(i = 0; i < size; i++){
Manufacturer(company[i]);
NewPrice(price[i], discount, size, 1);
}
//for loop which is working until i < size
//I have here 1 because I have if statement in the function
//there are two function links in the loop
//so when first function will be done program will go to next link
puts("\nNew price");
puts("\nManufacturer\tPrice");
//program just print New price then Manufacturer on next line an Price in next coloumn
for(i = 0; i < size; i++){
Manufacturer(company[i]);
NewPrice(price[i], discount, size, 0);
}
//for loop which is working until i < size
//I have here 0 because I have if statement in the function
//there are two function links in the loop
//so when first function will be done program will go to next link
return 0;
}
float NewPrice(float x, float y, int z, int k){
//function New price
int i;
//declaring variable i type integer
float Price;
//declaring variable Price type float
if(k == 0){
//if statement which is working because of the constant k
for(i = 0; i < z; i++){
Price = x * (1 - (y / 100));
}
//for loop which is working util i < z
//there is only one formula for calculating new price in the loop
printf("\t%.1f\n", Price);
//program prints new price
}
else {
printf("\t%.1f\n", x);
}
//else if k is not equal to 0 program prints x
return Price;
//program returns Price into main function
}
void Manufacturer(char company[]){
//function Manufacturer
printf("%-13s", company);
//program will print company in the first 13 cells and align it to the left side
}
void Input(int size, char company[size][15], float price[size]){
//function Input
int i;
//declaring variable i type integer
for(i = 0; i < size; i ++){
//for loop which is working util i < size
printf("Input name of the company #%d\n", i+1);
//program prints text and i+1
scanf("%s", company[i]);
//user input string company
do{
//do while loop which is working untill price[i] < 0
puts("Input price not less than 0");
//program prints text
scanf("%f", &price[i]);
//user input price[i]
}while(price[i] < 0);
}
}
float Discount(){
//function Discount
float discount;
//declaring variable discount type float
do{
//do while loop which is working untill discount will be out of range
puts("Input price not less than 0");
//program prints text
puts("Input discount in percentages (between 10 and 60)");
//program prints text
scanf("%f", &discount);
//user input discount
}while(discount > 60 || discount < 10);
return discount;
//program return discount to the main function
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment