MT4 130 and 138 errors - error-handling

I'm trying to handle TP and SL for orders, but I'm still getting errors. I want my stoploss to be at a moving average called MA_Slow and the takeprofit to a number of pips over my initial position. I'm getting 138s and 130s. Any ideas?
// if open position set sl at Slow_MA and tp if specified
for (int i = OrdersTotal(); i>=0; i-- )
if ( OrderSelect(i,SELECT_BY_POS) == true )
if ( OrderSymbol() == _Symbol )
if ( OrderType() == OP_BUY )
{
RefreshRates();
if ( Bid - OrderOpenPrice() > Slow_MA )
if ( OrderStopLoss() < Slow_MA )
{
retval = OrderModify( OrderTicket(), OrderOpenPrice(), NormalizeDouble(Slow_MA, Digits), NormalizeDouble(OrderOpenPrice() + ( TakeProfit * 0.0001 ),Digits), 5, Lime );
if(!retval) Print("Error in OrderModify, Buy Order #",OrderTicket() ," Error code=",GetLastError());
Print("Buy order ", OrderTicket(), " modified. SL = ", DecOut(OrderStopLoss(),5));
}
}
else // mod SL for Sell orders
{
RefreshRates();
if ( OrderOpenPrice() - Ask < Slow_MA )
if ( OrderStopLoss() > Slow_MA )
{
retval = OrderModify( OrderTicket(), OrderOpenPrice(), NormalizeDouble(Slow_MA, Digits), NormalizeDouble(OrderOpenPrice() - ( TakeProfit * 0.0001 ), Digits), 5, Lime );
if(!retval) Print("Error in OrderModify, Sell Order #",OrderTicket() ," Error code=",GetLastError());
Print("Sell order ", OrderTicket(), " modified. SL = ", DecOut(OrderStopLoss(),5));
}
}

Related

Calculate average packet travel speed in NS2 using AWK

I need to calculate average packet travel speed in ns2. I have to write this formula in awk program. But I have no idea how to do it.
n is the number of received packet, and s is the distance when the packet is transmitted. Any answer will be very helpfull. Thanks.
function topla( array ) {sum=0; for (i in array) {sum=sum+250/array[i];}return sum;}
BEGIN {
total_packets_sent = 0;
total_packets_received = 0;
total_packets_dropped = 0;
first_packet_sent = 0;
last_packet_sent = 0;
last_packet_received = 0;}
{event = $1; time = $2; node = $3; type = $4; reason = $5; packetid = $6;
if ( time < simulation_start || simulation_start == 0 )
simulation_start = time;
if ( time > simulation_end )
simulation_end = time;
if ( type == "AGT" ) {
nodes[node] = node; # to count number of nodes
if ( time < node_start_time[node] || node_start_time[node] == 0 )
node_start_time[node] = time;
if ( time > node_end_time[node] )
node_end_time[node] = time;
if ( event == "s" ) {
flows[node] = node; # to count number of flows
if ( time < first_packet_sent || first_packet_sent == 0 )
first_packet_sent = time;
if ( time > last_packet_sent )
last_packet_sent = time;
# rate
packets_sent[node]++;
total_packets_sent++;
# delay
pkt_start_time[packetid] = time;
}
else if ( event == "r" ) {
if ( time > last_packet_received )
last_packet_received = time;
# throughput
packets_received[node]++;
total_packets_received++;
# delay
pkt_end_time[packetid] = time;
}
}}`
END {
# delay
for ( pkt in pkt_end_time) {
end = pkt_end_time[pkt];
start = pkt_start_time[pkt];
delta = end - start;
if ( delta > 0 ) {
delay[pkt] = delta;
}
}
result=topla(delay)/total_packets_received;
printf(result)
}
I write this awk program. But it gives the division by zero attempted error.And I wrote the transmission range in the topla function as 250, but I did not get the results I wanted.How should I write the transmission range?

REGEXP_REPLACE pattern has to be const? Comparing strings in BigQuery

I'm trying to measure similarity between strings using Dice's Coefficient (aka Pair Similarity) in BigQuery. For a second I thought that I can do that using just standard functions.
Suppose I need to compare "gana" and "gano". Then I would "cook" these two strings upfront into 'ga|an|na' and 'ga|an|no' (lists of 2-grams) and do this:
REGEXP_REPLACE('ga|an|na', 'ga|an|no', '')
Then based on change in length I can calculate my coeff.
But once applied to the table I get:
REGEXP_REPLACE second argument must be const and non-null
Is there any workaround for that? With simple REPLACE() second argument can be a field.
Maybe there is a better way to do it? I know, I can do UDF instead. But I wanted to avoid them here. We are running big tasks and UDFs are generally slower (at least in my experience) and are subject to different concurrency limit.
You can have JavaScript code inside for BigQuery SQL queries.
To measure similarity you could use Levenshtein's distance with a query like this (from https://stackoverflow.com/a/33443564/132438):
SELECT *
FROM js(
(
SELECT title,target FROM
(SELECT 'hola' title, 'hello' target), (SELECT 'this is beautiful' title, 'that is fantastic' target)
),
title, target,
// Output schema.
"[{name: 'title', type:'string'},
{name: 'target', type:'string'},
{name: 'distance', type:'integer'}]",
// The function
"function(r, emit) {
var _extend = function(dst) {
var sources = Array.prototype.slice.call(arguments, 1);
for (var i=0; i<sources.length; ++i) {
var src = sources[i];
for (var p in src) {
if (src.hasOwnProperty(p)) dst[p] = src[p];
}
}
return dst;
};
var Levenshtein = {
/**
* Calculate levenshtein distance of the two strings.
*
* #param str1 String the first string.
* #param str2 String the second string.
* #return Integer the levenshtein distance (0 and above).
*/
get: function(str1, str2) {
// base cases
if (str1 === str2) return 0;
if (str1.length === 0) return str2.length;
if (str2.length === 0) return str1.length;
// two rows
var prevRow = new Array(str2.length + 1),
curCol, nextCol, i, j, tmp;
// initialise previous row
for (i=0; i<prevRow.length; ++i) {
prevRow[i] = i;
}
// calculate current row distance from previous row
for (i=0; i<str1.length; ++i) {
nextCol = i + 1;
for (j=0; j<str2.length; ++j) {
curCol = nextCol;
// substution
nextCol = prevRow[j] + ( (str1.charAt(i) === str2.charAt(j)) ? 0 : 1 );
// insertion
tmp = curCol + 1;
if (nextCol > tmp) {
nextCol = tmp;
}
// deletion
tmp = prevRow[j + 1] + 1;
if (nextCol > tmp) {
nextCol = tmp;
}
// copy current col value into previous (in preparation for next iteration)
prevRow[j] = curCol;
}
// copy last col value into previous (in preparation for next iteration)
prevRow[j] = nextCol;
}
return nextCol;
}
};
var the_title;
try {
the_title = decodeURI(r.title).toLowerCase();
} catch (ex) {
the_title = r.title.toLowerCase();
}
emit({title: the_title, target: r.target,
distance: Levenshtein.get(the_title, r.target)});
}")
Below is tailored for similarity
Was used in How to perform trigram operations in Google BigQuery? and based on https://storage.googleapis.com/thomaspark-sandbox/udf-examples/pataky.js by #thomaspark
SELECT text1, text2, similarity FROM
JS(
// input table
(
SELECT * FROM
(SELECT 'mikhail' AS text1, 'mikhail' AS text2),
(SELECT 'mikhail' AS text1, 'mike' AS text2),
(SELECT 'mikhail' AS text1, 'michael' AS text2),
(SELECT 'mikhail' AS text1, 'javier' AS text2),
(SELECT 'mikhail' AS text1, 'thomas' AS text2)
) ,
// input columns
text1, text2,
// output schema
"[{name: 'text1', type:'string'},
{name: 'text2', type:'string'},
{name: 'similarity', type:'float'}]
",
// function
"function(r, emit) {
var _extend = function(dst) {
var sources = Array.prototype.slice.call(arguments, 1);
for (var i=0; i<sources.length; ++i) {
var src = sources[i];
for (var p in src) {
if (src.hasOwnProperty(p)) dst[p] = src[p];
}
}
return dst;
};
var Levenshtein = {
/**
* Calculate levenshtein distance of the two strings.
*
* #param str1 String the first string.
* #param str2 String the second string.
* #return Integer the levenshtein distance (0 and above).
*/
get: function(str1, str2) {
// base cases
if (str1 === str2) return 0;
if (str1.length === 0) return str2.length;
if (str2.length === 0) return str1.length;
// two rows
var prevRow = new Array(str2.length + 1),
curCol, nextCol, i, j, tmp;
// initialise previous row
for (i=0; i<prevRow.length; ++i) {
prevRow[i] = i;
}
// calculate current row distance from previous row
for (i=0; i<str1.length; ++i) {
nextCol = i + 1;
for (j=0; j<str2.length; ++j) {
curCol = nextCol;
// substution
nextCol = prevRow[j] + ( (str1.charAt(i) === str2.charAt(j)) ? 0 : 1 );
// insertion
tmp = curCol + 1;
if (nextCol > tmp) {
nextCol = tmp;
}
// deletion
tmp = prevRow[j + 1] + 1;
if (nextCol > tmp) {
nextCol = tmp;
}
// copy current col value into previous (in preparation for next iteration)
prevRow[j] = curCol;
}
// copy last col value into previous (in preparation for next iteration)
prevRow[j] = nextCol;
}
return nextCol;
}
};
var the_text1;
try {
the_text1 = decodeURI(r.text1).toLowerCase();
} catch (ex) {
the_text1 = r.text1.toLowerCase();
}
try {
the_text2 = decodeURI(r.text2).toLowerCase();
} catch (ex) {
the_text2 = r.text2.toLowerCase();
}
emit({text1: the_text1, text2: the_text2,
similarity: 1 - Levenshtein.get(the_text1, the_text2) / the_text1.length});
}"
)
ORDER BY similarity DESC
REGEXP_REPLACE second argument must be const and non-null
Is there any
workaround for that?
Below is just an idea/direction to address above question applied to logic you described:
I would "cook" these two strings upfront into 'ga|an|na' and
'ga|an|no' (lists of 2-grams) and do this: REGEXP_REPLACE('ga|an|na',
'ga|an|no', ''). Then based on change in length I can calculate my
coeff.
The "workaround" is:
SELECT a.w AS w1, b.w AS w2, SUM(a.x = b.x) / COUNT(1) AS c
FROM (
SELECT w, SPLIT(p, '|') AS x, ROW_NUMBER() OVER(PARTITION BY w) AS pos
FROM
(SELECT 'gana' AS w, 'ga|an|na' AS p)
) AS a
JOIN (
SELECT w, SPLIT(p, '|') AS x, ROW_NUMBER() OVER(PARTITION BY w) AS pos
FROM
(SELECT 'gano' AS w, 'ga|an|no' AS p),
(SELECT 'gamo' AS w, 'ga|am|mo' AS p),
(SELECT 'kana' AS w, 'ka|an|na' AS p)
) AS b
ON a.pos = b.pos
GROUP BY w1, w2
Maybe there is a better way to do it?
Below is the simple example of how Pair Similarity can be approached here (including building bigrams sets and calculation of coefficient:
SELECT
a.word AS word1, b.word AS word2,
2 * SUM(a.bigram = b.bigram) /
(EXACT_COUNT_DISTINCT(a.bigram) + EXACT_COUNT_DISTINCT(b.bigram) ) AS c
FROM (
SELECT word, char + next_char AS bigram
FROM (
SELECT word, char, LEAD(char, 1) OVER(PARTITION BY word ORDER BY pos) AS next_char
FROM (
SELECT word, SPLIT(word, '') AS char, ROW_NUMBER() OVER(PARTITION BY word) AS pos
FROM
(SELECT 'gana' AS word)
)
)
WHERE next_char IS NOT NULL
GROUP BY 1, 2
) a
CROSS JOIN (
SELECT word, char + next_char AS bigram
FROM (
SELECT word, char, LEAD(char, 1) OVER(PARTITION BY word ORDER BY pos) AS next_char
FROM (
SELECT word, SPLIT(word, '') AS char, ROW_NUMBER() OVER(PARTITION BY word) AS pos
FROM
(SELECT 'gano' AS word)
)
)
WHERE next_char IS NOT NULL
GROUP BY 1, 2
) b
GROUP BY 1, 2

sql query vs linq to entity return different results

This is my sql query
SELECT TOP(10)projects.stat,
wo.stat,
sevt.restype,
sevt.resid,
restype.user2,
projects.prj_id,
projects.user3,
projects.user9,
wo.wonum,
wo.jobdesc,
sevt.sesid,
sevt.restype,
sevt.type,
sevt.t_start,
sevt.t_end,
sevt. mealstart,
sevt.mealend,
sevt. melstart2,
sevt.melend2,
sevt.melstart3,
sevt.melend3,
sevt.user2,
sevt.subactid,
sevt.ot_exempt,
sevt_ex.user5,
rescat.user1
FROM schedwin.projects
INNER JOIN schedwin.wo
ON projects.prj_id = wo.prj_id
INNER JOIN schedwin.sevt
ON wo.seqnum = sevt.seqnum
INNER JOIN schedwin.rsrce
ON sevt.resid = rsrce.resid
LEFT OUTER JOIN schedwin.pers
ON rsrce.recid = pers.recid
INNER JOIN schedwin.restype
ON sevt.rtype = restype.code
INNER JOIN schedwin.rescat
ON sevt.rcat = rescat.code
LEFT OUTER JOIN schedwin.sevt_ex
ON sevt.sesid = sevt_ex.sesid
WHERE ( Ltrim(Rtrim(projects.stat)) IN ( '1', '2' ) )
AND ( Ltrim(Rtrim(wo.stat)) = '6' )
AND ( ( ( sevt.restype = 5
OR sevt.restype = 0 )
AND ( Substring(restype.user2, 2, 1) = 'F'
AND Substring(restype.user2, 6, 1) = 'S' ) )
OR ( sevt.restype = 4 ) )
AND ( sevt.type = 0 )
AND rescat.groupid = 0
AND restype.groupid = 0
AND Len(Ltrim(wo.invoice)) > 0
AND Ltrim(wo.invoice) <> 'PENDING'
AND wo.userflag1 <> 1
AND Ltrim(sevt.t_start) = '1351728000'
ORDER BY projects.prj_id,
wo.wonum
I was converting in to Linq to Entity like below
var query =
(from PROJECTS in db.PROJECTS
join WOes in db.WOes on PROJECTS.PRJ_ID equals WOes.PRJ_ID
join SEVTs in db.SEVTs on WOes.SEQNUM equals SEVTs.SEQNUM
join RSRCEs in db.RSRCEs on SEVTs.RESID equals RSRCEs.RESID
join PERS in db.PERS on RSRCEs.RECID equals PERS.RECID into PERS_join
from PERS in PERS_join.DefaultIfEmpty()
join RESTYPEs in db.RESTYPEs on new { RTYPE = SEVTs.RTYPE } equals new { RTYPE = RESTYPEs.CODE }
join RESCATs in db.RESCATs on new { RCAT = SEVTs.RCAT } equals new { RCAT = RESCATs.CODE }
join SEVT_EX in db.SEVT_EX on SEVTs.SESID equals SEVT_EX.SESID into SEVT_EX_join
//join SEVT_EX in db.SEVT_EX on new { SESID = (String)SEVTs.SESID } equals new { SESID = SEVT_EX.SESID } into SEVT_EX_join
from SEVT_EX in SEVT_EX_join.DefaultIfEmpty()
where
(new string[] { "1", "2" }).Contains((PROJECTS.STAT.TrimEnd()).TrimStart()) &&
((WOes.STAT.TrimEnd()).TrimStart() == "6") &&
(((SEVTs.RESTYPE == 5 || SEVTs.RESTYPE == 0) &&
(RESTYPEs.USER2.Substring(2 - 1, 1) == "F" && RESTYPEs.USER2.Substring(6 - 1, 1) == "S")) || (SEVTs.RESTYPE == 0)) &&
(SEVTs.TYPE == 0) &&
(RESCATs.GROUPID == 0) &&
(RESTYPEs.GROUPID == 0 )&&
(int?)(WOes.INVOICE.TrimStart()).Length > 0 &&
WOes.INVOICE.TrimStart() != "PENDING" &&
WOes.USERFLAG1 != 1 &&
(SEVTs.T_START.TrimStart()) == (Booktime)
//(SEVTs.T_START.TrimStart()) == (Booktime)
// String.Compare(SEVTs.T_START.ToString().TrimStart(), "1351728000") >= 0
//Convert.ToInt32(SEVTs.T_START.TrimStart()) >= Convert.ToInt32(Booktime)
orderby
PROJECTS.PRJ_ID,
WOes.WONUM
select new
{
PROJECTS.PRJ_ID,
PROJECTS.USER3,
PROJECTS.USER9,
WOes.WONUM,
WOes.JOBDESC,
SEVTs.SESID,
SEVTs.RESTYPE,
SEVTs.TYPE,
SEVTs.T_START,
SEVTs.T_END,
SEVTs.MEALEND,
SEVTs.MELSTART3,
SEVTs.MELSTART2,
SEVTs.MELEND2,
Column1 = SEVTs.MELSTART2,
SEVTs.MELEND3,
SEVTs.USER2,
SEVTs.SUBACTID,
SEVTs.OT_EXEMPT,
USER5 = SEVT_EX.USER5,
SEVTs.GMT_OFFSET,
SEVTs.MEALSTART,
SEVTs.STANDARD,
RESCATs.USER1,
SEVTs.RESID
}).Take(10);
Definitely my sql query is return a correct records back but my Linq is not, any have any clue what am missing here please ?
Thanks
You have this line:
(((SEVT.restype = 5 or SEVT.restype = 0) and (substring(restype.User2,2,1) = 'F' and substring(restype.User2,6,1) = 'S')) or (SEVT.RESTYPE = 4))and
and in linq you have this
((SEVTs.RESTYPE == 5 || SEVTs.RESTYPE == 0) && (RESTYPEs.USER2.Substring(2 - 1, 1) == "F" && RESTYPEs.USER2.Substring(6 - 1, 1) == "S") && SEVTs.TYPE == 0)
First, Substring in 2-1 = 1 not 2. and the Logical Operations not equal

Filtering from multiple object ID

I'm trying to filter an eZPublish fetch.
I've got a class which has an object relationS attribute. My filter allows to fetch objects of this class filtered by the object relations attribute.
I've started using the Enhanced Object Relations Filtering extension (http://projects.ez.no/index.php/enhanced_object_relation_filter), but this one only works with "AND" conditions and I want "OR".
I was able to edit the file to add the "OR" logic and this is what I got:
<?php
class EORExtendedFilter
{
function CreateSqlParts( $params )
{
$db =& eZDB::instance();
$tables = array();
$joins = array();
// foreach filtered attribute, we add a join the relation table and filter
// on the attribute ID + object ID
foreach( $params as $param )
{
if ( !is_array( $param ) )
continue;
if ( !is_numeric( $param[0] ) )
{
$classAttributeId = eZContentObjectTreeNode::classAttributeIDByIdentifier( $param[0] );
}
else
{
$classAttributeId = $param[0];
}
// multiple objects ids
if ( is_array($param[1]) )
{
foreach( $param[1] as $objectId )
{
$join = array(); // 'OR' logic
if ( is_numeric( $objectId ) )
{
$tableName = 'eor_link_' . $objectId;
$tables[] = 'ezcontentobject_link ' . $tableName;
$join[] = $tableName . '.from_contentobject_id = ezcontentobject.id';
$join[] = $tableName . '.from_contentobject_version = ezcontentobject.current_version';
$join[] = $tableName . '.contentclassattribute_id = ' . $classAttributeId;
$join[] = $tableName . '.to_contentobject_id = ' . $objectId;
}
// 'OR' logic
$joins[] = $join;
}
}
// single object id
else
{
$objectId = $param[1];
$tableName = 'eor_link_' . $objectId;
$tables[] = 'ezcontentobject_link ' . $tableName;
$joins[] = $tableName . '.from_contentobject_id = ezcontentobject.id';
$joins[] = $tableName . '.from_contentobject_version = ezcontentobject.current_version';
$joins[] = $tableName . '.contentclassattribute_id = ' . $classAttributeId;
$joins[] = $tableName . '.to_contentobject_id = ' . $objectId;
}
}
if ( !count( $tables ) or !count( $joins ) )
{
$tables = $joins = '';
}
else
{
$tables = "\n, " . implode( "\n, ", $tables );
// 'OR' logic
if ( is_array($param[1]) )
{
$andClauses = array();
foreach ($joins as $attr)
{
$andClauses[] = implode( " AND\n ", $attr );
}
$joins = implode( " OR\n ", $andClauses ) . " AND\n ";
}
else
{
$joins = implode( " AND\n ", $joins ) . " AND\n ";
}
}
return array( 'tables' => $tables, 'joins' => $joins );
}
}
This extended attribute filter produces this string :
eor_link_126.from_contentobject_id = ezcontentobject.id AND eor_link_126.from_contentobject_version = ezcontentobject.current_version AND eor_link_126.contentclassattribute_id = 537 AND eor_link_126.to_contentobject_id = 126 OR (eor_link_127.from_contentobject_id = ezcontentobject.id AND eor_link_127.from_contentobject_version = ezcontentobject.current_version AND eor_link_127.contentclassattribute_id = 537 AND eor_link_127.to_contentobject_id = 127 AND
I know it misses some parenthesis so I edited the string to test it directly in phpMyAdmin. This is the query:
SELECT DISTINCT
ezcontentobject.*,
ezcontentobject_tree.*,
ezcontentclass.serialized_name_list as class_serialized_name_list,
ezcontentclass.identifier as class_identifier,
ezcontentclass.is_container as is_container
, ezcontentobject_name.name as name, ezcontentobject_name.real_translation
, a0.sort_key_int
FROM
ezcontentobject_tree,
ezcontentobject,ezcontentclass
, ezcontentobject_name
, ezcontentobject_attribute a0
, ezcontentobject_link eor_link_126
, ezcontentobject_link eor_link_127
WHERE
ezcontentobject_tree.parent_node_id = 1443 and
((eor_link_126.from_contentobject_id = ezcontentobject.id AND
eor_link_126.from_contentobject_version = ezcontentobject.current_version AND
eor_link_126.contentclassattribute_id = 537 AND
eor_link_126.to_contentobject_id = 126) OR
(eor_link_127.from_contentobject_id = ezcontentobject.id AND
eor_link_127.from_contentobject_version = ezcontentobject.current_version AND
eor_link_127.contentclassattribute_id = 537 AND
eor_link_127.to_contentobject_id = 127)) AND
a0.contentobject_id = ezcontentobject.id AND
a0.contentclassattribute_id = 191 AND
a0.version = ezcontentobject_name.content_version AND
( a0.language_id & ezcontentobject.language_mask > 0 AND
( ( ezcontentobject.language_mask - ( ezcontentobject.language_mask & a0.language_id ) ) & 1 )
+ ( ( ( ezcontentobject.language_mask - ( ezcontentobject.language_mask & a0.language_id ) ) & 2 ) )
<
( a0.language_id & 1 )
+ ( ( a0.language_id & 2 ) )
)
AND
ezcontentclass.version=0 AND
ezcontentobject_tree.contentobject_id = ezcontentobject.id AND
ezcontentclass.id = ezcontentobject.contentclass_id AND
ezcontentobject.contentclass_id IN ( 17 ) AND
ezcontentobject_tree.contentobject_id = ezcontentobject_name.contentobject_id and
ezcontentobject_tree.contentobject_version = ezcontentobject_name.content_version and
( ezcontentobject_name.language_id & ezcontentobject.language_mask > 0 AND
( ( ezcontentobject.language_mask - ( ezcontentobject.language_mask & ezcontentobject_name.language_id ) ) & 1 )
+ ( ( ( ezcontentobject.language_mask - ( ezcontentobject.language_mask & ezcontentobject_name.language_id ) ) & 2 ) )
<
( ezcontentobject_name.language_id & 1 )
+ ( ( ezcontentobject_name.language_id & 2 ) )
)
AND ezcontentobject_tree.is_invisible = 0
AND
ezcontentobject.language_mask & 3 > 0
ORDER BY a0.sort_key_int DESC
LIMIT 0, 10
The thing is, when I execute the query above, nothing is returned because the query never stops. The CPU hits 100% and I have to restart mysql which means it's not a syntax issue.
Here is the explain of the query :
If anyone has any clue about this it will be very helpful.
I've solved it by rewriting everything using eZPersistentObject::fetchObjectList().

how to auto test a C program use files?

I have a C program and I need to test it using a file containing some test data and output the results automatically. How can I do this? Should I modify the program or should I write another program using C or something else like Python? Which is easier?
Here is my C program:
int main()
{
double wh,sh,salary;
int num = 0;
int valid = 1;
printf("Please input two non-negative numbers as a employee's working hours in one week and salary per hour.\n");
printf("Notice that the salary per hour can't be greater than 1000\nAlso you can't input more than 10 sets of data\n");
printf("Input them like this:\n20,34\nthen enter the Enter key\n");
while(scanf("%lf,%lf",&wh,&sh) == 2 && num < 10)
{
if(sh <0 || wh <0)
{
printf("Salary per hour or salary per hour can't be negative!\n");
}
else if(wh > 168)
{
printf("Working hours in one week can't be more than 168!\n");
}
else if(sh > 1000)
{
printf("Salary can't be greater than 1000!\n");
}
else
{
num ++;
if(wh <= 40)
{
if(sh <= 1000)
{
salary = wh * sh;
}
else if(sh > 1000 )
{
salary = wh * 1000;
}
}
else if(wh > 40 && wh <= 50)
{
if(sh*1.5 < 1000)
{
salary = 40*sh + (wh-40)*1.5*sh;
}
else if(sh*1.5 > 1000 && sh < 1000)
{
salary = 40*sh + (wh-40)*1000;
}
else if(sh > 1000)
{
salary = wh * 1000;
}
}
else if(wh > 50)
{
if(sh*3 < 1000)
{
salary = 40*sh + 10*1.5*sh + (wh-50)*3*sh;
}
else if(sh*1.5 < 1000 && sh*3 >=1000)
{
salary = 40*sh + 10*1.5*sh + (wh-50)*1000;
}
else if(sh*1.5 >= 1000 && sh <= 1000)
{
salary = 40*sh + (wh-40)*1000;
}
else if(sh > 1000)
{
salary = wh*1000;
}
}
printf("The total working hours is %lf, and salary per hour is %lf, salary is %lf\n",wh,sh,salary);
}
}
return 0;
}
For this moment please ignore these literals floating around.
I suppose the file containing test data is like this:
1,2
34,34
67,43
...
I really have no idea how this test automation works,please help!
in cmd prompt
enter
c:\>myprog.exe < input.txt > output.txt
put all ur testcases in input.txt
ur output will print in the output.txt file