Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
remirz
/
iax0583
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
60cb3fc4
authored
Nov 26, 2018
by
remirz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
8aa1af5f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
129 additions
and
0 deletions
Homework 2/Homework2.c
Homework 2/Homework2.c
0 → 100644
View file @
60cb3fc4
#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
(
"
\n
Old price"
);
puts
(
"
\n
Manufacturer
\t
Price"
);
//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
(
"
\n
New price"
);
puts
(
"
\n
Manufacturer
\t
Price"
);
//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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment