| View previous topic :: View next topic |
| Author |
Message |
AndrewMan Grandmaster Cheater Supreme
Reputation: 0
Joined: 01 Aug 2007 Posts: 1257
|
Posted: Wed Jan 23, 2008 8:13 pm Post subject: Averager - My first c++ |
|
|
| Code: | #include<iostream>
using namespace std;
int main (void)
{
double dnumber1 = 0.0;
double dnumber2 = 0.0;
double dnumber3 = 0.0;
double daverage = 0.0;
cout << "please enter 3 numbers: " << endl;
cin >> dnumber1;
cin >> dnumber2;
cin >> dnumber3;
daverage = (dnumber1 + dnumber2 + dnumber3) / 3;
cout << "the average of the numbers are: " << daverage << endl << endl;
system("pause");
return 0;
} |
you type 3 numbers in, and it averages them. Kinda neat, huh?
_________________
|
|
| Back to top |
|
 |
wunder312355 Grandmaster Cheater
Reputation: -1
Joined: 14 May 2007 Posts: 568
|
Posted: Wed Jan 23, 2008 8:26 pm Post subject: |
|
|
endl twice?
Anyways, move forward to functions and stuff now.
otherwise GJ
|
|
| Back to top |
|
 |
spectrum Expert Cheater
Reputation: 0
Joined: 27 Mar 2007 Posts: 143
|
Posted: Wed Jan 23, 2008 9:55 pm Post subject: |
|
|
| GJ, keep it up!
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Wed Jan 23, 2008 10:30 pm Post subject: |
|
|
New challenge:
Make it so i can enter as many numbers as i want, not just 3
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Wed Jan 23, 2008 11:44 pm Post subject: |
|
|
| blankrider wrote: | New challenge:
Make it so i can enter as many numbers as i want, not just 3 |
argh you stole my suggestion.
|
|
| Back to top |
|
 |
Aikos Cheater
Reputation: 0
Joined: 26 Nov 2007 Posts: 47
|
Posted: Thu Jan 24, 2008 4:16 am Post subject: |
|
|
| blankrider wrote: | New challenge:
Make it so i can enter as many numbers as i want, not just 3 |
Any specification on how to stop the input?
|
|
| Back to top |
|
 |
Losplagos Expert Cheater
Reputation: 0
Joined: 21 Mar 2006 Posts: 172 Location: Knee deep in a c++ book
|
Posted: Thu Jan 24, 2008 6:26 am Post subject: |
|
|
| Aikos wrote: | | blankrider wrote: | New challenge:
Make it so i can enter as many numbers as i want, not just 3 |
Any specification on how to stop the input? |
Let me think a little.
_________________
Earthbound = 31337 |
|
| Back to top |
|
 |
AndrewMan Grandmaster Cheater Supreme
Reputation: 0
Joined: 01 Aug 2007 Posts: 1257
|
Posted: Thu Jan 24, 2008 11:50 am Post subject: |
|
|
Im trying but I can't figure it out.
Can you make dnumber infinate or something?
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Jan 24, 2008 12:58 pm Post subject: |
|
|
| Hint: loop until the user says otherwise
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Thu Jan 24, 2008 1:12 pm Post subject: |
|
|
| AndrewMan wrote: | | Can you make dnumber infinate or something? |
yes. look up std::vector
|
|
| Back to top |
|
 |
mer0x Advanced Cheater
Reputation: 0
Joined: 06 Jan 2008 Posts: 63
|
Posted: Thu Jan 24, 2008 5:55 pm Post subject: |
|
|
| Use for.
|
|
| Back to top |
|
 |
|