Jump to content

How to calculate the average of two numbers in a table

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
14 replies to this topic

#1
cismarel

cismarel

    Learning Programmer

  • Members
  • PipPipPip
  • 37 posts
Hy guys ! I created a database (.mdf) . Where I have a table. I have three columns where on each row of two columns i have a float and on the third column I want to display the average of the two numbers on the row. Please help!

Ps. Excuse my bad english:rolleyes:

#2
Davide

Davide

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 506 posts
By table, you mean dataGridView?

(Salut!)
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

#3
Davide

Davide

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 506 posts
[SIZE=2]int[/SIZE] averge = 10;
dataGridView1.Rows[0].Cells[3].Value = averge.ToString();

Instead of [0] use a for loop to loop through all the rows.

Mult Noroc!
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

#4
cismarel

cismarel

    Learning Programmer

  • Members
  • PipPipPip
  • 37 posts
Thanks! Esti din Romania?

#5
cismarel

cismarel

    Learning Programmer

  • Members
  • PipPipPip
  • 37 posts
Fii atent *** am.Attached File  prtsc..jpg   464.39K   511 downloads Am schimbat modul de introducere de la tabel la details(pt ca aveam prea multe coloane). Nu am multa experienta in c#. Eu vreau ca camplu Medie A1 sa fie read-only ( asta stiu sa fac) si sa afiseze (medie S1A1 + medie S2A1)/2. Multumesc pentru ajutor!

#6
cismarel

cismarel

    Learning Programmer

  • Members
  • PipPipPip
  • 37 posts
*** = c_u_m

#7
Davide

Davide

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 506 posts

cismarel said:

Fii atent *** am.[ATTACH=CONFIG]2875[/ATTACH] Am schimbat modul de introducere de la tabel la details(pt ca aveam prea multe coloane). Nu am multa experienta in c#. Eu vreau ca camplu Medie A1 sa fie read-only ( asta stiu sa fac) si sa afiseze (medie S1A1 + medie S2A1)/2. Multumesc pentru ajutor!

Nu ai multa experienta in C#? Bazele de date sunt o chestie destul de grea sa stii. Se pare ca stie Google ce stie. Pai,
medieA1.Text = (double.Parse(medieS1a1.Text) + double.Parse(medieS2A1))/2.ToString();

double.Parse("string") converteste din string in double.

P.S. -> Evita sa publici idea de aplicatie pe forumuri daca participi la concursuri. In cazul asta ai dat si screenshot... ce sa mai zic...
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

#8
Davide

Davide

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 506 posts

cismarel said:

Thanks! Esti din Romania?

Nu, am invatat romana din pasiune :)). (ironic)
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

#9
Davide

Davide

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 506 posts

cismarel said:

*** = c_u_m

LOL!

(For english speakers: c_um = how in romanian)
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics

#10
gaylo565

gaylo565

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 268 posts
If you are actually averaging the numbers in your db (.mdf file) and not your gridview there is an SQL function for average (AVG() i believe but my sql is a bit rusty so you probably want to check that out.) This will average your numbers before you querry them all into a c# object. This can be very adventageous when you are dealing with large amounts of data as you wont be spending large amounts of time querying numbers that you are going to average anyways; instead the averaging will be done on the db server and will only send u the pertinent info. I realize that if you need the full table for other calculations (or simply for display purposes) anyway, or are dealing with only a few pieces of data, than this is not usefull to you. I did think it was worth mentioning for others who are looking for the same sort of thing.

#11
cismarel

cismarel

    Learning Programmer

  • Members
  • PipPipPip
  • 37 posts
Thanks a lot guys !
For Davide: Merci pt sfat ;am 16 ani si fac aplicatia asta pt un concurs care e peste 2 luni, tocmai din cauza ca nuprea stiu baze de date m-am apucat de acum ( defapt inafara de partea wysiwyg ai lui c# 2008 nuprea stiu mult cod). Nu mai cunosc decat singur baiat (care e cu un an mai mare decat mine) care sa lucreze in c# ;deobicei la varsta mea copiii merg pe html sau php(dar mai rar) si cel mai frecvent pe powerpoint (in care imi e si sila sa fac proiect) deci nici nu ma pot gandi ca cineva imi poate fura ideea cu toate ca nu e una foarte stralucita pot spune ca mai degraba e muncitoreasca. Programul care mi-am propus sa-l fac vrea sa stocheze cam toate informatiile despre o scoala si sper sa-l reusesc sal fac pana la deadline. Merci mult pentru ajutor! :thumbup:
P.S. Am o sa am o gramada de intrebari.

#12
Deadlock

Deadlock

    Learning Programmer

  • Members
  • PipPipPip
  • 81 posts
I'm not gonna waste my time using google translator to help someone that doesn't really care to deliver his question clearly. USE ENGLISH!