New to the forums and i have a few questions.
Author |
Message |
Dormadon
|
Posted: Wed Mar 08, 2006 9:38 pm Post subject: New to the forums and i have a few questions. |
|
|
Hey guys, I was pointed to these forums by a friend and thought i would get into c++ and the community.
I Recently Started TAFE ( In Australia its like a secondary School after Year 12 )
I Started About 4 Weeks late and was left behind and was given a assessment the first day >_<.
Question is.
Read in temperatures in celsius for every day in hanyary.
Prompt the user with the day number:
e.g. "Enter temp for day 1:"
Print the average of all temperatures over 30 degrees, the
average if temperatures 20 to 30 degrees, and the average of
all temeratures below 20 degrees.
( Use a for loop)
I Can't Really talk to the teacher because i dont understand him well, Really Bad Asian Teacher that isnt helping... Not Being offensive to all Asians.
One off my online mates told me this was the answer.
c++: |
// header files
#include <iostream>
// so we dont have to type std::cin...
using namespace std;
// Number of days in Hanyary...go figure
#define DAYSINHANYARY 30
int main()
{
// variables
double temp = 0, // input temp
tempAbove30 = 0, // avg temp above 30
temp20to30 = 0, // avg temp 20-30
tempBelow20 = 0; // avg temp below 20
int countAbove30 = 0, // counting variable for averaging.
count20to30 = 0,
countBelow20 = 0;
// input
for (int i = 1; i <= DAYSINHANYARY; i++)
{
// get the input
cout << "enter the temperature for day " << i << ": ";
cin >> temp;
cout << endl;
// do averaging stuffs...
// above 30
if (temp > 30.0)
{
tempAbove30+=temp; // increment temp.
countAvove30++; // increment count (by 1)
}
// 20 to 30
if (temp < 30.0 && temp >= 20.0)
{
temp20to30+=temp;
count20to30++; // increment count (by 1)
}
// below 20
if (temp < 20.0)
{
tempBelow20+=temp;
countBelow20++; // increment count (by 1)
}
} // end of for loop
// print out averages
cout << "Average temp above 30: " << (tempAbove30 / (double)countAbove30) << endl;
cout << "Average temp between 20 and 30: " << (temp20to30 / (double)count20to30) << endl;
cout << "Average temp below 20: " << (tempBelow20 / (double)countBelow20) << endl;
return 0;
}
|
But i Dont Want the answer like that, i would like to know how he worked it out, Yet again he said he didnt know and most likely ripped it off a site.
Any Help Would be really GREAT!!!!.
If you do wish to help me tackle this task. I have a email
Craig-watson@hotmail.com OR Just explain in here for me.
Thanks alot guys  |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tony

|
Posted: Wed Mar 08, 2006 9:56 pm Post subject: (No subject) |
|
|
Australia, eh? That's pretty awesome, welcome
The code is very trivial if you read it carefully. (syntax highlighting helps, take a look at it now)
Basically there's a loop that counts from 1 to 30, and each time asks the user for the temperature of that day. Depening on the range, it is added to one of the counters, and the average is calculated at the end.
If you have more specific questions (like "what does this line / block / function does?"), it could be explained in further detail.
Good luck in your course. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Justin_
|
Posted: Wed Mar 08, 2006 11:50 pm Post subject: (No subject) |
|
|
Hey Dom, one thing you forgot to mention is you're credentials. What programming experience do you have? Are you brand new to C++?
Can you even compile the code you presented us with?
As Tony said, please make your questions specific. |
|
|
|
|
 |
md

|
Posted: Thu Mar 09, 2006 1:59 am Post subject: (No subject) |
|
|
Justin_ wrote: Hey Dom, one thing you forgot to mention is you're credentials. What programming experience do you have? Are you brand new to C++?
Can you even compile the code you presented us with?
As Tony said, please make your questions specific.
It seems pretty obvious that he is new to programing. However it seems like he can compile the code. His question is about how it works, not how to get it to work. And reapeating tony what tony said about asking questions doesn't contrbute anything new. Oh, and his name isn't Dom; it's Dormadon. I sugest that you think before posting next time.
Dormadon, sorry for the interuption. Unfortunately I'm left repeating Tony too: if you have any specific questions about the code just ask. |
|
|
|
|
 |
Justin_
|
Posted: Thu Mar 09, 2006 8:41 pm Post subject: (No subject) |
|
|
I don't need your criticism Cornflake, thanks. Please also understand your place in the world: you are nothing and you have no control over me. Feel free not even to reply to me because you tick me off with all the rude things you say.
He presented us with this entire source and didn't hint that he had any idea at all what was going on. That was why I wanted to know exactly what he knew so when I answer his questions I don't waste my time.
Sorry to waste everyones time with this post, but I don't like being attacked. |
|
|
|
|
 |
Tony

|
Posted: Thu Mar 09, 2006 10:50 pm Post subject: (No subject) |
|
|
I find that Justin_'s question on Dormadon's programming experience was valid.
Cornflake has went a bit too far with personal critisism.
Now lets stop spaming this thread with personal arguments. Thank you. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
md

|
Posted: Fri Mar 10, 2006 12:36 am Post subject: (No subject) |
|
|
Ok, I is sorry Justin_; just that more and more often people add posts that seem entirely frivilous to me... and it bugs teh hell outa me.
On the topic of the code, there is a lot that can be simplified (not nessesarily for good reason...); and you don't need the type casting at the end.
c++: |
// header files
#include <iostream>
// so we dont have to type std::cin...
using namespace std;
// Number of days in Hanyary...go figure
// you can use a constant variable here intead of a define. That means that // it can't be changed by another define later on.
const int DAYSINHANYARY = 30;
int main()
{
// variables
double temp = 0, // input temp
tempAbove30 = 0, // avg temp above 30
temp20to30 = 0, // avg temp 20-30
tempBelow20 = 0; // avg temp below 20
int countAbove30 = 0, // counting variable for averaging.
count20to30 = 0,
countBelow20 = 0;
// input
for (int i = 1; i <= DAYSINHANYARY; i++)
{
// get the input
cout << "Enter the temperature for day " << i << ": ";
cin >> temp;
cout << endl;
// do averaging stuffs...
// above 30
if (temp > 30.0)
{
tempAbove30+=temp; // increment temp.
countAvove30++; // increment count (by 1)
}
else if ( temp >= 20.0) // 20 to 30; since anything over 30 has already been counted, just check to be sure it's over 20
{
temp20to30+=temp;
count20to30++; // increment count (by 1)
}
else // below 20; everything else has been counted, no need for an if at all!
{
tempBelow20+=temp;
countBelow20++; // increment count (by 1)
}
} // end of for loop
// print out averages
cout << "Average temp above 30: " << (tempAbove30 / countAbove30) << endl;
cout << "Average temp between 20 and 30: " << (temp20to30 / count20to30) << endl;
cout << "Average temp below 20: " << (tempBelow20 / countBelow20) << endl;
return 0;
}
|
As for questions about how it works... here's some english-level psudo code:
code: |
for each day do:
ask for temperature
if the temperature is > 30 add it to the >30 temperature counter
otherwise if the temperature is > 20 add it to the >20 temperature counter
if neither of hte two above conditions is true add it to the <20 counter
output the averages for each counter (total temp / number of temperatures in the counter)
|
|
|
|
|
|
 |
wtd
|
Posted: Fri Mar 10, 2006 1:00 am Post subject: (No subject) |
|
|
Cleaned up a bit.
c++: | #include <iostream>
using namespace std;
const int DAYS_IN_HANYARY = 30;
int main()
{
double temp = 0,
tempAbove30 = 0,
temp20to30 = 0,
tempBelow20 = 0;
int countAbove30 = 0,
count20to30 = 0,
countBelow20 = 0;
for (int i = 1; i <= DAYS_IN_HANYARY; i++)
{
// get the input
cout << "Enter the temperature for day " << i << ": ";
cin >> temp;
cout << endl;
if (temp > 30.0)
{
tempAbove30 += temp;
countAvove30++;
}
else if (temp >= 20.0)
{
temp20to30 += temp;
count20to30++;
}
else
{
tempBelow20 += temp;
countBelow20++;
}
}
cout << "Average temp above 30: " << (tempAbove30 / countAbove30) << endl
<< "Average temp between 20 and 30: " << (temp20to30 / count20to30) << endl
<< "Average temp below 20: " << (tempBelow20 / countBelow20) << endl;
return 0;
}
|
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Justin_
|
Posted: Fri Mar 10, 2006 2:09 am Post subject: (No subject) |
|
|
Cornflakes wrote: Ok, I is sorry Justin_
No problem, I take back what I said also. |
|
|
|
|
 |
Dormadon
|
Posted: Sun Mar 12, 2006 7:17 pm Post subject: Reply |
|
|
I Am new to coding and programming etc.
And to answer a few questions, I dont understand Any off it >_<. They just gave me the sheet and said do it... |
|
|
|
|
 |
Dormadon
|
Posted: Sun Mar 12, 2006 7:41 pm Post subject: Teachers... |
|
|
Know he is going on about a different subject and i asked for help and if he could explain it to me some more and he reply's.
Its you bad luck you where late into this course
Well there goes my chance off passing  |
|
|
|
|
 |
wtd
|
Posted: Sun Mar 12, 2006 10:06 pm Post subject: (No subject) |
|
|
You're completely new to programming and they gave you this assignment with no background in the language or basic concepts?
http://tryruby.hobix.com |
|
|
|
|
 |
Ninja
|
Posted: Sun Mar 12, 2006 10:51 pm Post subject: (No subject) |
|
|
wtd wrote: You're completely new to programming and they gave you this assignment with no background in the language or basic concepts?
ya i know whats with that?..even this year in our programing class we walk in
teacher:"aight guys finish chapter 4-9 by the end of this month ill talk to u later.."
me:" WHHA! lol |
|
|
|
|
 |
|
|