about check the number from string - c

This is my plan. {i using linux(mac(xcode&terminal))}
Name of program is Tour Company.
Ask for the user's first name and the discount code (3 letters plus 1 digit, e.g. "AGF2",or 0 if no discount code available).
---so i will use fgets to get string , How check last number , [guide #1]---
When the user enters a name equal to "END", you have reached the end of the day.
---how check input string = 'end' [guide #2]---
For each customer, repeatedly ask date of the tour (dd/mm/yyyy), which tour, and the number of people going on the tour.
Available tours are "London" (800/person), "Paris" (1000/person),*"Rome" (1400 baht/person)* and "Moscow" (2500 baht/person).
If the user has a discount code, take 15% off the total price if there are 1-4 people on a tour, 20% for 5 or more people. ---check from #1 so i will use 2 function---
When the customer enters a date beginning with "00", print an invoice showing the customer name plus information about each booked tour: date, tour name, number of people, total price before discount, discount amount, total price after discount.
The invoice should also show the total price for this customer.
---how to check have 00 before date? [guide#3]---
[from #2]At the end of the day, print a summary showing the number of customers who had discount codes, number of customers without discount codes, the total money received for each of the four tour types before discounts, the total discounts for each tour type, and the
overall total money received.---I not have problem about this ---
I'm newbie of C programing
---I want to make this programs without using pointers---
Thanks for help.
Ps.I'm weak about using english, sorry about grammar & meaning.

You can use strcmp() or strncmp() ,to compare input with "end"
fgets(input,MAX_SIZE,stdin);
if(strncmp(input,"end",3)==0)
{
//you have reached the end of the day
}

Related

Sumproduct in Netezza

I want to calculate sumproduct in netezza table, where one column is fixed. In frist column (A) I have some numbers in DISCOUNT are discount factors. As a result I want to get sumproduct bewteen A and DISCOUNT, where DISCOUNT always start from first row.
Number in RESULTS:
14,54535 = 5/(1+2%)+3/(1+3%)+7/(1+4%),
9.737293 = 3/(1+2%)+7/(1+3%)
6.862745 = 7/(1+2%)
Always when copunting the next number in columns RESULT, we ignore the previous values from A, but always use the DISCOUNT from MATURITY=1 forward.
MATURITY
A
R
DISCOUNT
RESULT
1
5
2%
98.0392...%
14,54535...
2
3
3%
97.0874...%
9.737293...
3
7
4%
97.0874...%
6.862745...
Is the any way to do that in Neteza? Without using multiple joins for rates/discounts? Since the dimension of data can vary.

Average of a player

I have a record that contains stat for a certain cricket player.
It has columns having dates, oppositions, Runs, Balls, Dismissals, Match_Number.
I want to do a query (SQL SERVER) to find out the batting average where every runs (Sum) is to be added; innings having a count of all innings except DNB but dismissal should not have a count of "Not Out", "Retired Hurt", "DNB" grouped by the opposition.
Note : DNB means Did not Bat.
The query doesn't have the required number of innings to calculate the average
So the problem is can't gather information for a single entity (count of no. of innings) having two set of parameters.
Without DNB
Without DNB, Not Out, Retired Hurt.
Please suggest.
You can put a case expression within an aggregate to exclude certain rows from a count/sum/average etc. So you could use something like this:
SELECT a.Opposition,
Matches = COUNT(*),
Innings = COUNT(CASE WHEN a.Dismissal <> 'DNB' THEN 1 END),
Runs = SUM(a.Runs),
Average = SUM(a.Runs) / NULLIF(COUNT(CASE WHEN a.Dismissal NOT IN ('DNB', 'Not Out', 'Retired not out') THEN 1 END), 0)
FROM dbo.SRTundlkarODI AS a
GROUP BY a.Opposition;
N.B. I have wrapped the COUNT for the average in NULLIF(<exp>, 0) so that should the batsmen have never got out you avoid a divide by zero error.

working on a payroll calculation program

I'm working on a payroll calculation and I have to get it to loop
while name= karen:
name = (input("enter employees name"))
if karen>0:
hours=float(input("enter hours worked"))
rate=float(input('enter hourly rate'))
total= (hours)*(rate)+(overtimetotal)
print (total)
# when over time
if hours>40:
overtimerate=1.50
overtimetotal= (total)* (overtimerate)
print (overtimetotal)
my instructor said "There should not be an input for overtimehours. You are calculating it by taking the hours-40
You need to calculate the total as total=hours*rate+overtimetotal
You need to have a while loop to checking the name !="0"
everything in the loop block will be indented."
Im lost at what to write to start the loop.

Counting Columns with conditions, assigning values based on count

I have a table with call logs. I need to assign time slots for next call based on which time slot the phone number was reachable in.
The relevant columns of the table are:
Phone Number | CallTimeStamp
CallTimeStamp is a datetime object.
I need to calculate the following:
Time Slot: From the TimeStamp, I need to calculate the count for each time slot (eg. 0800-1000, 1001-1200, etc.) for each phone number. Now, if the count is greater than 'n' for a particular time slot, then I need to assign that time slot to that number. Otherwise, I select a default time slot.
Weekday Slot: Same as above, but with weekdays.
Priority: Basically a count of how many times a number was reached
Here's I have gone about solving these issues:
Priority
To calculate the number of times a phone number is called is straight forward. If a number exists in the call log, I know that it was called. In that case, the following query will give me the call count for each number.
SELECT DISTINCT(PhoneNumber), COUNT(PhoneNumber) FROM tblCallLog
GROUP BY PhoneNumber
However, my problem is that I need to change the values in the field Count(PhoneNumber) based on the value in that column itself. How do I go about achieving this? (eg. If Count(PhoneNumber) gives me a value > 20, I need to change it to 5).
Time Slot / Weekday
This is where I'm completely stumped and am looking for the "database" way of doing things.
Unfortunately, I can't get out of my iterative process of thinking. For example, if I was aggregating for a certain phone number (say '123456') and in a certain time slot (say between 0800-1000 hrs), I can write a query like this:
DECLARE #T1Start time = '08:00:00.0000'
DECLARE #T2End time = '10:00:00.0000'
SELECT COUNT(CallTimeStamp) FROM tblCallLog
WHERE PhoneNumber = '123456' AND FORMAT(CallTimeStamp, 'hh:mm:ss') >= #T1Start AND FORMAT(CallTimeStamp, 'hh:mm:ss') < #T2End
Now, I could go through each and every Distinct Phone Number in the table, count the values for each time slot and then assign a slot value for the phone number. However, there has to be a way that does not involve me iterating through a database.
So, I am looking for suggestions on how to solve this.
Thanks
You can use DATEPART Function to get week day slot.
To calculate time slot you can try dividing number of minutes from beginning of day and dividing it by size of the time slot. It would return you slot number. You can use either CASE statement to translate it to proper string or look table where you can store slot descriptions.
SELECT
PhoneNumber
, DATEPART(WEEKDAY, l.CallTimeStamp) AS DayOfWeekSlot
, DATEDIFF(MINUTE, CONVERT(DATE, l.CallTimeStamp), l.CallTimeStamp) / 120 AS TwoHourSlot /*You can change number of minutes to get different slot size*/
, COUNT(*) AS Count
FROM tblCallLog l
GROUP BY PhoneNumber
, DATEPART(WEEKDAY, l.CallTimeStamp)
, DATEDIFF(MINUTE, CONVERT(DATE, l.CallTimeStamp), l.CallTimeStamp) / 120
You could try this to return the phone number, the day of the week and a 2 hour slot. If the volume of calls is greater than 20 the value is set to 5 (not sure why to 5?). The code for the 2 hour section is adapted from this question How to Round a Time in T-SQL where the value 2 in (24/2) is the number of hours in your time period.
SELECT
PhoneNumber
, DATENAME(weekday,CallTimeStamp) as [day]
, CONVERT(smalldatetime,ROUND(CAST(CallTimeStamp as float) * (24/2),0)/(24/2)) AS RoundedTime
, CASE WHEN COUNT(*) > 20 THEN 5 ELSE COUNT(*) END
FROM
tblCallLog
GROUP BY
PhoneNumber
, DATENAME(weekday,dateadd(s,start_ts,'01/01/1970'))

MATLAB receipt print random values issue

I have a project where I must make the following;
You have a small business and you sell 6 different products. Choose your products
and their prices within the range of 20p to £25.00 (these could be completely fictitious). Your
shop has 4 employees, one of whom will be at the till at the time of purchase.
Your task is to write MATLAB code to prepare a receipt for a fictitious transaction as explained
below.
There is a customer at the till. They want to purchase 3 random products with specific
quantities for each. For example, the customer wants 2 cappuccinos, 1 croissant and 6 raspberry
muffins.
(1) Select randomly 3 products from your list. For each product choose a random quantity
between 1 and 9.
(2) Calculate the total cost.
(3) Choose randomly the staff member to complete the transaction.
(4) Suppose that the price includes 20% VAT. Calculate the amount of VAT included in the price.
(6) Prepare the receipt as text in the MATLAB command window. Use the current date and time
(check datestr(now,0)).
Your code should output the receipt in the format shown in the picture. There should be
60 symbols across. Choose our own shop name.
My code so far is the following:
clear all
clc
close all
items = {'apples ','carrots ','tomatoes','lemons ','potatoes','kiwis '};% products
price = {3.10, 1.70, 4.00, 1.65, 9.32, 5.28};% item prices. I set spaces for each entry in order to maintain the border format.
employee = {'James','Karina','George','Stacey'};%the employees array
disp(sprintf('+-----------------------------------------------+'));
disp(sprintf('|\t%s \t\t\tAlex''s Shop |\n|\t\t\t\t\t\t\t\t\t\t\t\t|', datestr(now,0)));
totalPrice = 0;
for i = 1:3
randItems = items {ceil(rand*6)};
randprice = price {ceil(rand*6)};
randQuantity = ceil(rand*9);% random quantity from 1 to 9 pieces
randEmployee = employee{ceil(rand*4)};
itemTotal = randprice * randQuantity;%total price of individual item
totalPrice = totalPrice + itemTotal;
disp(sprintf('|\t%s\t (%d) x %.2f = £ %.2f \t\t\t|', randItems, randQuantity, randprice, itemTotal))
end
disp(sprintf('|\t\t\t\t-----------------------------\t|'));
disp(sprintf('|\t\t\t\t\t\t\t\t\t\t\t\t|\n|\t Total to pay \t £ %.2f\t\t\t\t|',totalPrice));
disp(sprintf('|\t VAT \t\t\t\t £ %.2f\t\t\t\t| \n|\t\t\t\t\t\t\t\t\t\t\t\t|', totalPrice*0.2));
disp(sprintf('|\tThank you! You have been served by %s\t|\t', randEmployee));
disp(sprintf('+-----------------------------------------------+'));
My issue of course is the following. Upon choosing a random item from the items list, I then choose a random price to assign as well. I don't want this though. I would like to find a way to assign a preset price to each item to be printed automatically when generating a random item to be added to the basket. I hope this explanation is sufficient for you, if you have any questions feel free to ask. Thank you in advance.
When you write
randItems = items {ceil(rand*6)};
randprice = price {ceil(rand*6)};
you calculate a random index into the array items, and then you calculate a random index into the array price. If you instead assign the index you calculate via ceil(rand*6) to a separate variable, called e.g. index, you can re-use it to pick, say, item #3 from both items and price. Thus, the ith item will always show up with the ith price.

Resources