MATLAB receipt print random values issue - arrays

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.

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.

How do I use StreamReader to assign values from a .txt file to a 2D array in Visual Studio?

In this program, I have to assign values to a 2D array by retrieving data from the following text file:
Product 1$Vanilla Ice Cream$20$1.99
Product 2$Glazed Donut$10$2.50
Product 3$Small Muffin$25$2.99
Product 4$Large Muffin$20$3.99
Product 5$Small Lollipop$40$1
Product 6$Large Lollipop$30$2
Each row is a different product, and the "$" separates the different facts about the products. For example, Product 1 is Vanilla Ice Cream, there are of it 20 available, and it costs 1.99 dollars.
For intRow = 0 To 4
strLine = inFile.ReadLine()
For intCol = 0 To 5
strFields(intRow, intCol) = Split(","c)(intCol)
ListBox1.Items.Add(strFields)
Next
Next
Here's the code I've tried so far. First, I'm trying to read the data from the first row, and then the data from each column as the variable corresponding to the row increases.

Count from column in a table by referencing a column in another table

I wasn't really sure what to title this but this is what I'm trying to do:
I have a table of teams:
teamid | city | name
and I have a table of games played:
gameid | teamid | points
What I'm trying to do is tally the total points scored in all games played by the 'Raptors'.
I've tried it this way:
SELECT COUNT(points) AS "Raptors Points" FROM TEAMS, GAMES
WHERE name = 'Raptors' AND TEAMS.teamid = GAMES.teamid;
and this way:
SELECT COUNT(points) AS "Raptors Points" FROM (SELECT * FROM
TEAMS JOIN GAMES ON TEAMS.teamid = GAMES.teamid WHERE
name = 'Raptors') AS foo;
Both result in a table displaying only points from one of the games (the first one) instead of a total count from all games.
I'm really stumped as to what I'm doing wrong. Any suggestions?
Thanks
Most likely you are seeing the wrong value and thinking it's a proper value. You need to change COUNT(points) with SUM(points)
Count will give you the total number of records, SUM will give you the total number of points
BTW your first query should work if you fix that

Sum of cost amount calculation

I have attached the screenshot. Most probably that the image itself will explain my logic. Let me paste the code I have used in the fields. Product Info1 field which hold Y & N.
RemainingCosu2=If(Invoice Line Items::Product Info1 = GetAsText ("N"); Sum(Cost Total) - Invoice Line Items::VendPaid_total;0)
RemainingCosu1=If(Vendor Status="Partly Paid"; RemainingCosu2; 0)
What should I do to fix this issue?. Please check the screenshot:
Filemaker has no SumIf() function. You need to create a calculation field in the LineItems table, along the lines of:
If ( Paid = "N" ; Cost )
then sum this field at the invoice level (and/or summarize it at the LineItems table itself), instead of the Cost field.
--
BTW, it is much more convenient to define Boolean (yes/no) fields as Number and use the values of 1 for True, 0 (or empty) for False. Then the calculation can be simply:
If ( not Paid ; Cost )

about check the number from string

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
}

Resources