tough homework 3
Roy and Tal are playing basketball. During the season there are 10 games. Write a program that captures the number of points scored by each of them in each of the 10 games and displays as output:
A. For each of the games the player who scored more points.
B. the total points of both players together.
25 Replies
" class Program
{
static void Main(string[] args)
{
int tal, roi;
for (int i = 1; i <= 10; i++)
{
Console.WriteLine("enter tals throws");
tal = int.Parse(Console.ReadLine());
Console.WriteLine("enter rois throws");
roi = int.Parse(Console.ReadLine());
}
}
}
}"
this is what i have come up with so far
i am just not so sure about how i am supposed to procced with A
do you know how to compare numbers?
define "compare"
static void Main(string[] args)
{
int tal, roi,roisum=0,talsum=0, sum=0;
for (int i = 1; i <= 10; i++)
{
Console.WriteLine("enter tals throws");
tal = int.Parse(Console.ReadLine());
talsum = talsum + tal;
Console.WriteLine("enter rois throws");
roi = int.Parse(Console.ReadLine());
roisum = roisum + roi;
sum = roisum + talsum;
}
Console.WriteLine("total throws=" + sum);
}
}
}
i think that covers B but i still dont understand how to do A
as in, compare two numbers and tell which one is higher
yeah but its in for
so?
so how exactely am i supposed to do it
like what am i supposed to write
if(tal > roi)
seems like a good start.ok
class Program
{
static void Main(string[] args)
{
int tal, roi,roisum=0,talsum=0, sum=0;
for (int i = 1; i <= 10; i++)
{
Console.WriteLine("enter tals throws");
tal = int.Parse(Console.ReadLine());
talsum = talsum + tal;
Console.WriteLine("enter rois throws");
roi = int.Parse(Console.ReadLine());
roisum = roisum + roi;
sum = roisum + talsum;
if (tal > roi)
{
Console.WriteLine("tal scored more");
}
else
{
Console.WriteLine("roi scored more");
}
}
Console.WriteLine("total throws=" + sum);
}
}
}
is this good ?
Seems to do the trick.
this is supposed to be submited on paper and it will be graded
I wonder if perhaps you are supposed to take input BEFORE doing any output
instead of doing output gradually
have you covered arrays at all up to this point?
do you want me to put "if" outside of "for"
I'd prefer if you answered my question.
Moving the if currently would only let you compare the result of a single round, not all 10
whats arrays
then you likely have not.
in the qustion i am asked about everysingle game sepreatly
in a
and in B its about total
so i put it out outside
can definately interpret A to be that it expects a "table" of sorts, but if you have not covered arrays yet then its a safe bet you dont need to do that
how would arrays look like
maybe i covered it and i just dont know what its called in english
int[] myIntArray;
does it function difrently then a reglur int
yes, it stores more than one
any intger can store more then one
not
an int more than one
. I mean more than one int
but dont i alrady have for for this
oh
yeah that very complacited and i defenitly did not do arrey yet