hi my name is Elvis and i am building a program that it has to be submitted today and i cannot find the way yo finish it. the program is this::
1. If all 3 numbers in any given row, column, or diagonal (8 possibilities in all) are all odd (i.e.,any combination of only Hearts and Clubs), a score of 100 is computed for that one row, column or diagonal. Examples of these 8 possibilities are shown below:
Note: You will need to write a mathematical equation for each row, column, and diagonal (8 equations in all) that will compute the score for that row, column and diagonal. You can accomplish this without using any branching statements.
2. Compute the total score by adding up all 8 individual scores computed for each row, column diagonal in step 1.
NOW MY PROBLEM IS THAT I GET THE RANDOM NUMBERS AND EVERYTHING BUT THE EQUATION THAT I NEED TO BUILD TO MAKE ODDS BE 100 IT IS WITHOUT IF STATEMENT, THE PROFESSOR SAID THAT WITH MODULUS % WE SHOULD BE ABLE TO DO IT. CAN SOMEBODY HELP ME THANK YOU...
i think i dont understand what has it to do with modals but try this
if n=3,x=5
y[10][10];
int k=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
y[i][j]=k;
k++;
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(i==j||i+j==n-1)
cout<<y[i][j];
}
ofcourse this is not a complete code but the others are includes and simple things
int main()
{
//declaring variables
int seed = 0; //Declaration for seed
int no1= 0;
int no2= 0;
int no3= 0;
int no4= 0;
int no5= 0;
int no6= 0;
int no7= 0;
int no8= 0;
int no9= 0;
//Set the seed to be the number of seconds since 1970
seed = time(0);
//Initialize srand function with seed
srand(seed);
so i have everything right what i cannot do is the equation that makes that if one of the 3 rows is all odds it is going to be 100 this is the picture of the example that he made...
Perhaps you should explain that again... preferably from the beginning.
I don't see what there is to get about any random numbers - they were never mentioned.
Edit: well, the code more or less explains it.
And what on earth is
no1 no3
no5
no7 no9
supposed to be? There are either 0 or 8 diagonals here, but certainly not 2.
THE PROFESSOR SAID THAT WITH MODULUS % WE SHOULD BE ABLE TO DO IT.
Yes. If a number mod 2 results in 1, the number is odd.
Write a C++ program that implements a game we’ll call the “hearts/clubs game”. The requirements of the game are outlined below
a. Generate 9 random numbers having possible values from 3 to 6 - including both 3 and 6. (must use srand and rand C++ functions to perform this)
b. Note: A different sequence of random numbers must be generated each time your program is run.
c. Display the character representation of the 9 random numbers in a 3x3 grid as shown below:
no1 no2 no3
no4 no5 no6
no7 no8 no9
where no1, no2, etc., corresponds to the variable names corresponding to each of the random numbers.
Typecast the number to a character as shown below for no1:
(char)no1
in order to display the character representation of that number.
Note that there are “---“ displayed between the numbers in the horizontal rows and the “|” symbol between numbers in the vertical columns.
d. Your program will compute a total score based on the values of the random numbers. The rules for computing the total score is given below:
1. If all 3 numbers in any given row, column, or diagonal (8 possibilities in all) are all odd (i.e.,any combination of only Hearts and Clubs), a score of 100 is computed for that one row, column or diagonal. Examples of these 8 possibilities are shown below:
Note: You will need to write a mathematical equation for each row, column, and diagonal (8 equations in all) that will compute the score for that row, column and diagonal. You can accomplish this without using any branching statements.
2. Compute the total score by adding up all 8 individual scores computed for each row, column diagonal in step 1.
so that is the whole homework so i did so far all the graphics and random things but now to be able to display is a row colum or diagonal is odd so 100 i do not have any clue. HELP
Well, like I said no1%2 will result in 1 if no1 is odd and 0 otherwise. And what can you do with these results?
Hint: addition, (integer) division and multiplication will help you here (in that order).
i think you gave me the perfect idea maybe if i said that no1+no2+no3 is = to row1 and the i say that row1%2 if it is like that then i can multiply by 100 and if it is no odd is going to be 0 otherwise it is going to be 100
Well, as you already noticed, calculating the modulo after adding doesn't make much sense, as the sum will be odd both for 1 and 3 odd numbers in the row. Aside from that, you're more or less on the right track.
So how about that: modulo, addition, (integer) division and multiplication (in that order).
thank you very much but i am still receiving the error of
1>c:\temp\lab2out\lab2outp2.cpp(36): warning C4244: '=' : conversion from 'time_t' to 'int', possible loss of data
1>c:\temp\lab2out\lab2outp2.cpp(39): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1> lab2out.vcxproj -> C:\temp\lab2out\Debug\lab2out.exe
int main()
{
//declaring variables
int seed = 0; //Declaration for seed
int no1= 0; //declaring random number
int no2= 0; //declaring random number
int no3= 0; //declaring random number
int no4= 0; //declaring random number
int no5= 0; //declaring random number
int no6= 0; //declaring random number
int no7= 0; //declaring random number
int no8= 0; //declaring random number
int no9= 0; //declaring random number
int row1= 0; //equation variable
int row2= 0; //equation variable
int row3= 0; //equation variable
int column1= 0; //equation variable
int column2= 0; //equation variable
int column3= 0; //equation variable
int diagonal1= 0; //equation variable
int diagonal2= 0; //equation variable
//Set the seed to be the number of seconds since 1970
seed = time(0);
//Initialize srand function with seed
srand (seed);
how can i fix that problem of the warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int',
Those aren't errors. They are warnings, telling you time(0) returns a time_t and srand() only wants an integer. You can safely ignore them, or you can cast the value if you really don't want to look at the warning.
And is there a reason that row1, etc. are equal to the average value of the row/whatever? I thought for each row/col/diag of 3 odds you got 100 points. I didn't see an average come into the picture at all.
EDIT:
If you really don't want to see the warning, you can get rid of the "seed" variable entirely (it's unnecessary) and use srand(static_cast<unsignedint>(time(0))); or something.