Combining coverpoints to create an aggregate - code-coverage

`define A 'd1
`define B 'd2
`define C 'd3
`define D 'd4
`define E 'd5
`define F 'd6
`define I 'd7
`define J 'd8
module testModule(input clk,
input CReset,
input[4;0] Opcode_P0I1,
input[4;0] Opcode_P0I2,
input[4;0] Opcode_P0I3,
input[4;0] Opcode_P0I4,
input[4;0] Opcode_P1I1,
input[4;0] Opcode_P1I2,
input[4;0] Opcode_P1I3,
input[4;0] Opcode_P1I4,
input P0V,
input P1V,
input P0IsFe,
input P1IsFe,
input P0I1PAllow,
input P0I2PAllow,
input P0I3PAllow,
input P0I4PAllow,
input P1I1PAllow,
input P1I2PAllow,
input P1I3PAllow,
input P1I4PAllow,
input I1VT0,
input I1VT1,
input I1VT2,
input I1VT4,
input I2VT0,
input I2VT1,
input I2VT2,
input I2VT3,
input I3VT0,
input I3VT1,
input I3VT2,
input I3VT3,
input I4VT0,
input I4VT1,
input I4VT2,
input I4VT3,
input[3:0] P0TId,
input[3:0] P1TId);
covergroup cg_Abc #(posedge clk);
option.per_instance = 1;
cp_P0I1_IsSquare: coverpoint Opcode_P0I1 iff (P0V == 1 && P0IsFe == 1 && P0I1PAllow == 1 && (I1VT0 && P0TId == 2**0 || I1VT1 && P0TdId == 2**1 || I1VT2 && P0TId == 2**2 || I1VT3 && P0TId == 2**3)) {option.weight = 0;type_option.weight = 0; bins derp = {`A,`B,`C};}
cp_P0I2_IsSquare: coverpoint Opcode_P0I2 iff (P0V == 1 && P0IsFe == 1 && P0I2PAllow == 1 && (I2VT0 && P0TId == 2**0 || I2VT1 && P0TdId == 2**1 || I2VT2 && P0TId == 2**2 || I2VT3 && P0TId == 2**3)) {option.weight = 0;type_option.weight = 0; bins derp = {`A,`B,`C};}
cp_P0I3_IsSquare: coverpoint Opcode_P0I3 iff (P0V == 1 && P0IsFe == 1 && P0I3PAllow == 1 && (I3VT0 && P0TId == 2**0 || I3VT1 && P0TdId == 2**1 || I3VT2 && P0TId == 2**2 || I3VT3 && P0TId == 2**3)) {option.weight = 0;type_option.weight = 0; bins derp = {`A,`B,`C};}
cp_P0I4_IsSquare: coverpoint Opcode_P0I4 iff (P0V == 1 && P0IsFe == 1 && P0I4PAllow == 1 && (I4VT0 && P0TId == 2**0 || I4VT1 && P0TdId == 2**1 || I4VT2 && P0TId == 2**2 || I4VT3 && P0TId == 2**3)) {option.weight = 0;type_option.weight = 0; bins derp = {`A,`B,`C};}
cp_P1I1_IsSquare: coverpoint Opcode_P1I1 iff (P1V == 1 && P1IsFe == 1 && P1I1PAllow == 1 && (I1VT0 && P1TId == 2**0 || I1VT1 && P1TdId == 2**1 || I1VT2 && P1TId == 2**2 || I1VT3 && P1TId == 2**3)) {option.weight = 0;type_option.weight = 0; bins derp = {`A,`B,`C};}
cp_P1I2_IsSquare: coverpoint Opcode_P1I2 iff (P1V == 1 && P1IsFe == 1 && P1I2PAllow == 1 && (I2VT0 && P1TId == 2**0 || I2VT1 && P1TdId == 2**1 || I2VT2 && P1TId == 2**2 || I2VT3 && P1TId == 2**3)) {option.weight = 0;type_option.weight = 0; bins derp = {`A,`B,`C};}
cp_P1I3_IsSquare: coverpoint Opcode_P1I3 iff (P1V == 1 && P1IsFe == 1 && P1I3PAllow == 1 && (I3VT0 && P1TId == 2**0 || I3VT1 && P1TdId == 2**1 || I3VT2 && P1TId == 2**2 || I3VT3 && P1TId == 2**3)) {option.weight = 0;type_option.weight = 0; bins derp = {`A,`B,`C};}
cp_P1I4_IsSquare: coverpoint Opcode_P1I4 iff (P1V == 1 && P1IsFe == 1 && P1I4PAllow == 1 && (I4VT0 && P1TId == 2**0 || I4VT1 && P1TdId == 2**1 || I4VT2 && P1TId == 2**2 || I4VT3 && P1TId == 2**3)) {option.weight = 0;type_option.weight = 0; bins derp = {`A,`B,`C};}
cp_P0I1_IsCircle: coverpoint Opcode_P0I1 iff (P0V == 1 && P0I1PAllow == 0 && (I1VT0 && P0TId == 2**0 || I1VT1 && P0TdId == 2**1 || I1VT2_DE2 && P0TId == 2**2 || I1VT3 && P0TId == 2**3)) {option.weight = 0;type_option.weight = 0; bins bxx = {`D,`E,`F,`G,`H,`I,`J};}
cp_P0I2_IsCircle: coverpoint Opcode_P0I2 iff (P0V == 1 && P0I2PAllow == 0 && (I2VT0 && P0TId == 2**0 || I2VT1 && P0TdId == 2**1 || I2VT2_DE2 && P0TId == 2**2 || I2VT3 && P0TId == 2**3)) {option.weight = 0;type_option.weight = 0; bins bxx = {`D,`E,`F,`G,`H,`I,`J};}
cp_P0I3_IsCircle: coverpoint Opcode_P0I3 iff (P0V == 1 && P0I3PAllow == 0 && (I3VT0 && P0TId == 2**0 || I3VT1 && P0TdId == 2**1 || I3VT2_DE2 && P0TId == 2**2 || I3VT3 && P0TId == 2**3)) {option.weight = 0;type_option.weight = 0; bins bxx = {`D,`E,`F,`G,`H,`I,`J};}
cp_P0I4_IsCircle: coverpoint Opcode_P0I4 iff (P0V == 1 && P0I4PAllow == 0 && (I4VT0 && P0TId == 2**0 || I4VT1 && P0TdId == 2**1 || I4VT2_DE2 && P0TId == 2**2 || I4VT3 && P0TId == 2**3)) {option.weight = 0;type_option.weight = 0; bins bxx = {`D,`E,`F,`G,`H,`I,`J};}
cp_P1I1_IsCircle: coverpoint Opcode_P1I1 iff (P1V == 1 && P1I1PAllow == 0 && (I1VT0 && P1TId == 2**0 || I1VT1 && P1TdId == 2**1 || I1VT2 && P1TId == 2**2 || I1VT3 && P1TId == 2**3)) {option.weight = 0;type_option.weight = 0; bins bxx = {`D,`E,`F,`G,`H,`I,`J};}
cp_P1I2_IsCircle: coverpoint Opcode_P1I2 iff (P1V == 1 && P1I2PAllow == 0 && (I2VT0 && P1TId == 2**0 || I2VT1 && P1TdId == 2**1 || I2VT2 && P1TId == 2**2 || I2VT3 && P1TId == 2**3)) {option.weight = 0;type_option.weight = 0; bins bxx = {`D,`E,`F,`G,`H,`I,`J};}
cp_P1I3_IsCircle: coverpoint Opcode_P1I3 iff (P1V == 1 && P1I3PAllow == 0 && (I3VT0 && P1TId == 2**0 || I3VT1 && P1TdId == 2**1 || I3VT2 && P1TId == 2**2 || I3VT3 && P1TId == 2**3)) {option.weight = 0;type_option.weight = 0; bins bxx = {`D,`E,`F,`G,`H,`I,`J};}
cp_P1I4_IsCircle: coverpoint Opcode_P1I4 iff (P1V == 1 && P1I4PAllow == 0 && (I4VT0 && P1TId == 2**0 || I4VT1 && P1TdId == 2**1 || I4VT2 && P1TId == 2**2 || I4VT3 && P1TId == 2**3)) {option.weight = 0;type_option.weight = 0; bins bxx = {`D,`E,`F,`G,`H,`I,`J};}
cr_P0I1I2_IsSqauarexIsCircle : cross cp_P0I1_IsSquare,cp_P0I2_IsCircle{option.weight = 0;type_option.weight = 0;}
cr_P0I2I3_IsSqauarexIsCircle : cross cp_P0I2_IsSquare,cp_P0I3_IsCircle{option.weight = 0;type_option.weight = 0;}
cr_P0I3I4_IsSqauarexIsCircle : cross cp_P0I3_IsSquare,cp_P0I4_IsCircle{option.weight = 0;type_option.weight = 0;}
AggregateCov1 : ?
cr_P1I1I2_IsSqauarexIsCircle : cross cp_P1I1_IsSquare,cp_P1I2_IsCircle{option.weight = 0;type_option.weight = 0;}
cr_P1I2I3_IsSqauarexIsCircle : cross cp_P1I2_IsSquare,cp_P1I3_IsCircle{option.weight = 0;type_option.weight = 0;}
cr_P1I3I4_IsSqauarexIsCircle : cross cp_P1I3_IsSquare,cp_P1I14_IsCircle{option.weight = 0;type_option.weight = 0;}
AggregateCov2 : ?
endgroup
cg_Abc cg_Abc_inst = new();
endmodule
I am looking for AggregateCov1 which tells if any of cr_P0I1I2_IsSqauarexIsCircle,cr_P0I2I3_IsSqauarexIsCircle,cr_P0I3I4_IsSqauarexIsCircle is a hit. Essentially meaning I have at least one square and a circle adjacent to each other in the group [Opcode_P0I1,Opcode_P0I2,Opcode_P0I3,Opcode_P0I4].
Also looking for AggregateCov2 which tells if I have at least one square and a circle adjacent to each other in the group [Opcode_P0I1,Opcode_P0I2,Opcode_P0I3,Opcode_P0I4] or [Opcode_P1I1,Opcode_P1I2,Opcode_P1I3,Opcode_P1I4]

There is no need to do this as you need to hit the AND of all coverpoints a,b,c to get 100% coverage of this covergroup.
But if you insist, you can use a coverpoint expression
AggregateCoverpoint: coverpoint v_a | v_b | v_c;

Using assign statements to create new wires, makes this problem go away.

Related

String Task Codeforces Problem - https://codeforces.com/problemset/problem/118/A

https://codeforces.com/problemset/problem/118/A
my code:
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
string str;
cin >> str;
for(int i=0; i<sizeof(str); i++)
{
if(str[i] >= 'A' && str[i] <= 'Z')
str[i]+=32;
{
if(str[i] >= 'a' && str[i] <= 'z' && str[i] != 'a' && str[i] != 'e' && str[i] != 'i' && str[i] != 'o' && str[i] != 'u' && str[i] != 'A' && str[i] != 'E' && str[i] != 'I' && str[i] != 'O' && str[i] != 'U')
cout << "." << str[i];
}
}
return 0;
}
Where is the problem in this code because it gives wrong when I submit?
I am not seeing any problem, could anyone help me to detect?
In the question they have included 'y' as a vowel too. I changed some other stuff too (like, use i<str.size() not i<sizeof(str) ), try the following code it will get accepted :
int main()
{
string str;
cin >> str;
for(int i=0; i<str.size(); i++)
{
char temp;
temp = str[i];
if(temp >= 'A' && temp <= 'Z')
temp = tolower(temp);
if(temp != 'a' && temp != 'e' && temp != 'i' && temp != 'o' && temp != 'u' && temp != 'y')
cout << "." << temp;
}
return 0;
}

Why am I getting a mass of errors in my nested || statement?

Right, why am I getting a mass of errors in my nested || operator when there is no reason behind this?
Below is the code and the screenshot.
Thank you.
Error Log Screenshot
if(BarTime != Time[0])
{
if(hammerHeadClose < hammerHeadOpen){
if (bearHammerHead >= Transform(candleBodyLength,2))
if (bearHammerHandle!=0 && (bearHammerHead / bearHammerHandle) <= hammerHandlePct)
if (bullRetracementCandle!=0 && (bearHammerHead / bullRetracementCandle) <= hammerHeadPct)
}
else if (hammerHeadClose > hammerHeadOpen){
if (bearHammerHead >= Transform(candleBodyLength,2))
if (bearHammerHandle!=0 && (bearHammerHead / bearHammerHandle) <= hammerHandlePct)
if (bullRetracementCandle!=0 && (bearHammerHead / bullRetracementCandle) <= hammerHeadPct)
}
if (bearHammerHead >= Transform(candleBodyLength,2))
if (bearHammerHandle!=0 && (bearHammerHead / bearHammerHandle) <= hammerHandlePct)
if (bullRetracementCandle!=0 && (bearHammerHead / bullRetracementCandle) <= hammerHeadPct)
if (bullRetracementCandle!=0 && (initialTrendBearCandle / bullRetracementCandle) <= retracePercentage)
if (bullRetracementCandle >= Transform(candleBodyLength,2))
if (iMA(NULL,0,Period_TrendFast,0, AM_TrendFast,PRICE_CLOSE,1) < iMA(NULL,0,Period_TrendSlow,0,AM_TrendSlow,PRICE_CLOSE,1))
if (iMA(NULL,0,Period_MomentumFast,0,AM_MomentumFast,PRICE_CLOSE,1) < iMA(NULL,0,Period_MomentumSlow,0,AM_MomentumSlow,PRICE_CLOSE,1))
if (NewBar)
if (spread <= MaxSpread)
if (hourOfDay >= startingHour && hourOfDay < endingHour)
if (OrdersTotal()== 0) {
OrderSend(....);
}
}
It is difficult to know what you are trying to achieve with the code posted. Generally, if statements use the following rules:
if(Condition) // Header of the operator and condition
{
Block 1 of operators // If the condition is true, then..
composing body 1 //..the operators composing body 1 are executed
}
Your code has lots of conditions without anything to execute. For example:
if(hammerHeadClose < hammerHeadOpen)
{
if(bearHammerHead >= Transform(candleBodyLength,2))
if(bearHammerHandle!=0 && (bearHammerHead / bearHammerHandle) <= hammerHandlePct)
if(bullRetracementCandle!=0 && (bearHammerHead / bullRetracementCandle) <= hammerHeadPct)
}
This code does not actually do anything. You have nested if statements, but your final if statement needs to execute something, like so:
if(hammerHeadClose < hammerHeadOpen)
{
if(bearHammerHead >= Transform(candleBodyLength,2))
if(bearHammerHandle!=0 && (bearHammerHead / bearHammerHandle) <= hammerHandlePct)
if(bullRetracementCandle!=0 && (bearHammerHead / bullRetracementCandle) <= hammerHeadPct)
{ /* Code to execute if previous 3 if statements conditions are met */ }
}
Your final block of 11 nested if statement would result in OrderSend() if all conditions were true, it is your first set of if-else which do not make sense. Hopefully this explanation will help.

What's wrong with this C++ code lottery guessing game?

I am making a simple lottery game application, where three random numbers between 0 and 10 are generated, if the user gets all three in the right order, they get 1 million. If they get one right then they win 10 dollars, and if they get all three but not in order, they win a thousand, if two are matching then they get $1,000. and if they get none right then they get nothing.
Here's my code here.
int main()
{
cout << "Hello, this is the lottery! Three random numbers between 0 and 10 will be generated. Guess what they are and the order!" << endl;
char answer;
cout << "Do you want to play? (y or n): " << endl;
cin >> answer;
while (answer == 'y' || 'Y')
{
srand((unsigned)time(NULL));
int ran1 = rand() % 10;
int ran2 = rand() % 10;
int ran3 = rand() % 10;
int guess1, guess2, guess3;
cout << "Enter your first number guess: " << endl;
cin >> guess1;
cout << "Enter your second number guess: " << endl;
cin >> guess2;
cout << "Enter your third number guess: " << endl;
cin >> guess3;
if ((guess1 != ran1 || ran2 || ran3) && (guess2 != ran1 || ran2 || ran3) && (guess3 != ran1 || ran2 || ran3))
cout << "You won no money. Sucks for you." << endl;
else
if ((guess1 == ran1 || ran2 || ran3) || (guess2 == ran1 || ran2 || ran3) || (guess3 == ran1 || ran2) || ran3)
cout << "You won 10 dollars!" << endl;
else
if ((guess1 && guess2 == ran1 && ran2) || (guess1 && guess3 == ran1 && ran3) || (guess2 && guess3 == ran2 && ran3))
cout << "You won 100 dollars!" << endl;
else
if ((guess1 == ran1 || ran2 || ran3) && (guess2 == ran1 || ran2 || ran3) && (guess3 == ran1 || ran2 || ran3))
cout << "You won 1 thousand dollars! good job!" << endl;
else
if ((guess1 == ran1) && (guess2 == ran2) && (guess3 == ran3))
cout << "You won 1 million dollars! jackpot!" << endl;
cout << "The numbers were " << ran1 << "," << ran2 << "," << ran3 << endl;
cout << "Play again?(y or n): " << endl;
cin >> answer;
if (answer == 'y')
continue;
else
break;
}
cout << "Game Over" << endl;
system("pause");
return 0;
}
when i run this code, things don't go right with the decisions. All it says is "You won no money. sucks for you". Idk what's wrong maybe its something simple but can someone help? Thanks.
if ((guess1 != ran1 || ran2 || ran3) && (guess2 != ran1 || ran2 || ran3) && (guess3 != ran1 || ran2 || ran3))
should be
if ((guess1 != ran1 || guess1 != ran2 || guess1 != ran3) && (guess2 != ran1 || guess2 != ran2 || guess2 != ran3) && (guess3 != ran1 || guess3 != ran2 || guess3 != ran3))
It is not the order of the conditionals, even though there are flaws there as well, but is the way in which you have written the conditionals.
(guess1 == ran1 || ran2) is different than (guess1 == ran1 || guess1 == ran2)
This is because in c++ a number other than 0 evaluates to true. This is why it is evaluating to true every time.
For example, say guess1 = 1, ran1 = 2, and ran2 = 3, then
(guess1 == ran1 || guess1 == ran2) will evaluate to false, but
(guess1 == ran1 || ran2) will evaluate to true.

Objective C - Only part of an if condition working

I have an if statement and the statement is only being run on the fist third of the condition (before the fist 'or' (||).
if (((day == 1) && (period == 1)) || ((day == 3) && (period == 3)) || ((day = 5) && (period == 1)))
{
NSLog(#"Return Line 1");
}
The condition is only met when day = 1 and period = 1. Could someone help me get the other arrangements working in the condition. Thank you in advance.
if (((day == 1) && (period == 1)) || ((day == 3) && (period == 3)) || ((day == 5) && (period == 1)))
{
NSLog(#"Return Line 1");
}
In your code there is only one = instead of ==
The error in your code is ((day = 5) && (period == 1))

Objective-c Making levels for an iPhone game

I have a question game in which I ask the user some questions and depending on how fast the user answers correctly and what level the user is in I want the user to get different amounts of xp/ progress for the progress view that I have.
So I have a global variable called 'levelInt' which holds the value of what level the user is in (max level is 20). I also have a label that prints the the 'levelInt' variable and a progress view that shows your progress for getting into higher level/shows progress for your current level. I also have a timer which counts down from 2 minutes and depending on how fast you answer this question you get more xp/more progress for the progress view. I set it up like this:
totalSeconds is the timer
levelInt is the global variable that hold the value of the level the user is in
progressView is the progress bar the show the remaining xp until next level
and the code:
if ( levelInt == 0 && totalSeconds > 100){
progressView.progress = .60;
}else if ( levelInt == 0 && totalSeconds <= 100 ){
progressView.progress = .40;
}else if ( levelInt == 0 && totalSeconds > 80 ){
progressView.progress = .20;
}else if ( levelInt == 0 && totalSeconds <= 80 ) {
progressView.progress = .10;
}else {
progressView.progress = .05;
}
if ( levelInt == 1 && totalSeconds > 100){
progressView.progress = .55;
}else if ( levelInt == 1 && totalSeconds <= 100 ){
progressView.progress = .35;
}else if ( levelInt == 1 && totalSeconds > 80 ){
progressView.progress = .15;
}else if ( levelInt == 1 && totalSeconds <= 80 ) {
progressView.progress = .05;
}else {
progressView.progress = .02;
}
if ( levelInt == 2 && totalSeconds > 100){
progressView.progress = .50;
}else if ( levelInt == 2 && totalSeconds <= 100 ){
progressView.progress = .30;
}else if ( levelInt == 2 && totalSeconds > 80 ){
progressView.progress = .10;
}else if ( levelInt == 2 && totalSeconds <= 80 ) {
progressView.progress = .05;
}else {
progressView.progress = .02;
}
if ( levelInt == 3 && totalSeconds > 100){
progressView.progress = .45;
}else if ( levelInt == 3 && totalSeconds <= 100 ){
progressView.progress = .25;
}else if ( levelInt == 3 && totalSeconds > 80 ){
progressView.progress = .05;
}else if ( levelInt == 3 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 4 && totalSeconds > 100){
progressView.progress = .40;
}else if ( levelInt == 4 && totalSeconds <= 100 ){
progressView.progress = .20;
}else if ( levelInt == 4 && totalSeconds > 80 ){
progressView.progress = .05;
}else if ( levelInt == 4 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 5 && totalSeconds > 100){
progressView.progress = .35;
}else if ( levelInt == 5 && totalSeconds <= 100 ){
progressView.progress = .15;
}else if ( levelInt == 5 && totalSeconds > 80 ){
progressView.progress = .05;
}else if ( levelInt == 5 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 6 && totalSeconds > 100){
progressView.progress = .30;
}else if ( levelInt == 6 && totalSeconds <= 100 ){
progressView.progress = .10;
}else if ( levelInt == 6 && totalSeconds > 80 ){
progressView.progress = .05;
}else if ( levelInt == 6 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 7 && totalSeconds > 100){
progressView.progress = .28;
}else if ( levelInt == 7 && totalSeconds <= 100 ){
progressView.progress = .08;
}else if ( levelInt == 7 && totalSeconds > 80 ){
progressView.progress = .04;
}else if ( levelInt == 7 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 8 && totalSeconds > 100){
progressView.progress = .26;
}else if ( levelInt == 8 && totalSeconds <= 100 ){
progressView.progress = .07;
}else if ( levelInt == 8 && totalSeconds > 80 ){
progressView.progress = .05;
}else if ( levelInt == 8 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 9 && totalSeconds > 100){
progressView.progress = .24;
}else if ( levelInt == 9 && totalSeconds <= 100 ){
progressView.progress = .05;
}else if ( levelInt == 9 && totalSeconds > 80 ){
progressView.progress = .03;
}else if ( levelInt == 9 && totalSeconds <= 80 ) {
progressView.progress = .02;
}else {
progressView.progress = .02;
}
if ( levelInt == 10 && totalSeconds > 100){
progressView.progress = .22;
}else if ( levelInt == 10 && totalSeconds <= 100 ){
progressView.progress = .04;
}else if ( levelInt == 10 && totalSeconds > 80 ){
progressView.progress = .03;
}else if ( levelInt == 10 && totalSeconds <= 80 ) {
progressView.progress = .02;
}else {
progressView.progress = .02;
}
if ( levelInt == 11 && totalSeconds > 100){
progressView.progress = .20;
}else if ( levelInt == 11 && totalSeconds <= 100 ){
progressView.progress = .04;
}else if ( levelInt == 11 && totalSeconds > 80 ){
progressView.progress = .03;
}else if ( levelInt == 11 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 12 && totalSeconds > 100){
progressView.progress = .18;
}else if ( levelInt == 12 && totalSeconds <= 100 ){
progressView.progress = .04;
}else if ( levelInt == 12 && totalSeconds > 80 ){
progressView.progress = .03;
}else if ( levelInt == 12 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 13 && totalSeconds > 100){
progressView.progress = .16;
}else if ( levelInt == 13 && totalSeconds <= 100 ){
progressView.progress = .04;
}else if ( levelInt == 13 && totalSeconds > 80 ){
progressView.progress = .03;
}else if ( levelInt == 13 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 14 && totalSeconds > 100){
progressView.progress = .14;
}else if ( levelInt == 14 && totalSeconds <= 100 ){
progressView.progress = .04;
}else if ( levelInt == 14 && totalSeconds > 80 ){
progressView.progress = .03;
}else if ( levelInt == 14 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 15 && totalSeconds > 100){
progressView.progress = .12;
}else if ( levelInt == 15 && totalSeconds <= 100 ){
progressView.progress = .03;
}else if ( levelInt == 15 && totalSeconds > 80 ){
progressView.progress = .03;
}else if ( levelInt == 15 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 16 && totalSeconds > 100){
progressView.progress = .10;
}else if ( levelInt == 16 && totalSeconds <= 100 ){
progressView.progress = .03;
}else if ( levelInt == 16 && totalSeconds > 80 ){
progressView.progress = .03;
}else if ( levelInt == 16 && totalSeconds <= 80 ) {
progressView.progress = .03;
}else {
progressView.progress = .02;
}
if ( levelInt == 17 && totalSeconds > 100){
progressView.progress = .08;
}else if ( levelInt == 17 && totalSeconds <= 100 ){
progressView.progress = .02;
}else if ( levelInt == 17 && totalSeconds > 80 ){
progressView.progress = .02;
}else if ( levelInt == 17 && totalSeconds <= 80 ) {
progressView.progress = .02;
}else {
progressView.progress = .02;
}
if ( levelInt == 18 && totalSeconds > 100){
progressView.progress = .06;
}else if ( levelInt == 18 && totalSeconds <= 100 ){
progressView.progress = .02;
}else if ( levelInt == 18 && totalSeconds > 80 ){
progressView.progress = .02;
}else if ( levelInt == 18 && totalSeconds <= 80 ) {
progressView.progress = .02;
}else {
progressView.progress = .02;
}
if ( levelInt == 19 && totalSeconds > 100){
progressView.progress = .04;
}else if ( levelInt == 19 && totalSeconds <= 100 ){
progressView.progress = .02;
}else if ( levelInt == 19 && totalSeconds > 80 ){
progressView.progress = .02;
}else if ( levelInt == 19 && totalSeconds <= 80 ) {
progressView.progress = .02;
}else {
progressView.progress = .02;
}
if ( levelInt ==20 && totalSeconds > 100){
progressView.progress = .04;
}else if ( levelInt == 20 && totalSeconds <= 100 ){
progressView.progress = .02;
}else if ( levelInt == 20 && totalSeconds > 80 ){
progressView.progress = .02;
}else if ( levelInt == 20 && totalSeconds <= 80 ) {
progressView.progress = .02;
}else {
progressView.progress = .02;
}
The problem is that whenever I answer correctly fast then the 20 seconds, the progress view only adds about .10. Should I do progressView.progress = progressView.progress + (amount)?
The first or the second statement will always validates true,
therefor the last three if statements will never be validated.
Numbers cannot validate false to both <= 100 and > 100.
Numbers validating false to > 100 are always <= 100.
if ( i > 100 )
{
// All numbers above 100
}
else if ( i <= 100 )
{
// All numbers lower than or equal to 100
}
else if ( i > 80 )
{
// Never reached
}
else if ( i <= 80 )
{
// Never reached
}
else
{
// Never reached
}
2 better ways to do the job :
1 : create a function (linear ?) to compute your progress.
float progress (int level , int seconds);
2 : use an array (your read from a file for better use)
//float values [levels][cases];
//float values [21][3];
static init
float values[0] = {.10,.20,.60};
float values[1] = ....
int acase ;
if (totalSeconds <= 80){
acase=0;
}else{
// your are > 80 here
if (totalSeconds <= 100){
acase=1;
}else{
// your are > 100 here
acase=2;
}
}
progressView.progress = values[levelInt,acase];
and it's done (more shorter i think)
you can of course add cases (here 3)

Resources