C
C#2y ago
daniel1

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
daniel1
daniel12y ago
" 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
Pobiega
Pobiega2y ago
do you know how to compare numbers?
daniel1
daniel12y ago
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
Pobiega
Pobiega2y ago
as in, compare two numbers and tell which one is higher
daniel1
daniel12y ago
yeah but its in for
Pobiega
Pobiega2y ago
so?
daniel1
daniel12y ago
so how exactely am i supposed to do it like what am i supposed to write
Pobiega
Pobiega2y ago
if(tal > roi) seems like a good start.
daniel1
daniel12y ago
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 ?
Pobiega
Pobiega2y ago
Seems to do the trick.
daniel1
daniel12y ago
this is supposed to be submited on paper and it will be graded
Pobiega
Pobiega2y ago
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?
daniel1
daniel12y ago
do you want me to put "if" outside of "for"
Pobiega
Pobiega2y ago
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
daniel1
daniel12y ago
whats arrays
Pobiega
Pobiega2y ago
then you likely have not.
daniel1
daniel12y ago
in the qustion i am asked about everysingle game sepreatly in a and in B its about total so i put it out outside
Pobiega
Pobiega2y ago
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
daniel1
daniel12y ago
how would arrays look like maybe i covered it and i just dont know what its called in english
Pobiega
Pobiega2y ago
int[] myIntArray;
daniel1
daniel12y ago
does it function difrently then a reglur int
Pobiega
Pobiega2y ago
yes, it stores more than one
daniel1
daniel12y ago
any intger can store more then one
Pobiega
Pobiega2y ago
not an int more than one. I mean more than one int
daniel1
daniel12y ago
but dont i alrady have for for this oh yeah that very complacited and i defenitly did not do arrey yet