Need help with this c++ source code! DOnt understand what some stuff mean.


 
Thread Tools Search this Thread
Top Forums Programming Need help with this c++ source code! DOnt understand what some stuff mean.
# 1  
Old 04-09-2011
Question Need help with this c++ source code! Dont understand what some of the syntax means.

Okay so I am just starting programming c++. I just started started to red "C++ for Dummies yesterday and theres a lot of things I do not understand from this book and this source code especially. I will first post the full source code and then post questions about certain thing, usually what they do and how they help. Anyways here it is! (I understand there are comments yet I still don't understand some stuff Smilie, sorry)

Code:
 
//
// Program to convert temperature from Celsius degree
// units into Fahrenheit degree units:
// Fahrenheit = Celsius * (212 - 32)/100 + 32
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
// enter the temperature in Celsius
int celsius;
cout << “Enter the temperature in Celsius:”;
cin >> celsius;
// calculate conversion factor for Celsius
// to Fahrenheit
int factor;
factor = 212 - 32;
// use conversion factor to convert Celsius
// into Fahrenheit values
int fahrenheit;
fahrenheit = factor * celsius/100 + 32;
// output the results (followed by a NewLine)
cout << “Fahrenheit value is:”;
cout << fahrenheit << endl;
// wait until user is ready before terminating program
// to allow the user to see the program results
system(“PAUSE”);
return 0;
}

Okay so these are the things I do not undersand. In these lines, i understand it declares a variable and names it "factor" but I dont understand why on the next line it says "factor = 212 - 32;" what does the equals sign mean and what do the integers 212 and 32 do? also what the minus sign do. I think this is an expression but i dont understand it. Do I need it? Please help! Explain it in non geeky please guys! I am pretty newbie. Here is the source code:

Code:
 int factor;
factor = 212 - 32;

Next would be this expression and how it works. Is this the formula to convert Celsius to Fahrenheit? Please explain everything and what ALL things do. equals sign, etc. Non geeky please I am pretty newbie right now.

Code:
fahrenheit = factor * celsius/100 + 32;

Well that's it for now! I hope you wizards answer this soon. I will continue to read and continue to stumble countless times. Anyways guys have a good day! Smilie

Last edited by orszhak; 04-09-2011 at 03:53 PM.. Reason: mistakes made
# 2  
Old 04-09-2011
Is this homework??? I'd understand if you have questions about the syntax, but about basic mathematical expressions???

I wouldn't even know how to explain this "geeky" (as you put it). Those are mathematical expressions / formulas. The minus sign is an operator, just as in mathematics, and does the same thing as it does there: substract 2 numbers.
# 3  
Old 04-09-2011
Thanks, Its not homework by the way.

I'am currently reading c++ for Dummies and it gave me this source code for the calculator. Anyways I wanted to know what this meant:
Code:
factor = 212 - 32;

Why are their the integers 212 and 32? What is an operator, more what does it do?

Next would be this one I believe it is the expression to calculate the conversion?
Code:
fahrenheit = factor * celsius/100 + 32;

Does the 32 here connect with the 32 on the other line? What about the "100"?

Anyways my real question is on the first one. Anyways hope you guys can help!

---------- Post updated at 01:00 PM ---------- Previous update was at 12:58 PM ----------

Ohhhhh thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Bad substituion error : Dont understand why

Hi Folks - I'm getting the following error message when executing my script: $ chmod +x Winexe_Admin.sh $ ./Winexe_Admin.sh Script Name: Winexe_Admin.sh Script Name without EXT: Winexe_Admin ./Winexe_Admin.sh: line 43: ${_MAINPATH}${_LOGPATH}${LOGPATH$}${_YEAR}_${_MONTH}${_DAY}: bad... (2 Replies)
Discussion started by: SIMMS7400
2 Replies

2. Programming

Help me to understand strange 'typedef ... ' in some source...

Working on some source I've found some strange declaration in included header file. I am looking for someone's help to understand me that syntax's, as it is fine (it is compiled without any complain,) but for me it seems out of any sense! Acctually, it warning by CC compiler: " Warning: Implicit... (1 Reply)
Discussion started by: alex_5161
1 Replies

3. UNIX for Dummies Questions & Answers

help me to understand this code

Hi guys can you please help me to understand this code . tmpArray=(${line//=/ }) Please next time open a new thread in the appropriate forum and use code tags (6 Replies)
Discussion started by: sandhya.gilla
6 Replies

4. Programming

Breakpoints dont work in Codeblocks, code does not build

Hey so I've written a program and it crashes every time I run it. I tried placing breakpoints to see what was going but to my surprise they do not work! I've placed them anywhere and they do not stop the execution of the program. In fact if I add code and hit rebuild it doesn't even build that... (1 Reply)
Discussion started by: Cambria
1 Replies

5. Shell Programming and Scripting

help can't understand the code

Hi All, Good day, i'm just wondering what is the meaning of this code? COUNT_EXTRACTED_FILE=`${ECHO_CMD} "${SE_IN_PATH}${SE_IN_FILE}" | ${AWK_CMD} -F"__" '{print $2}'` Thanks, -niks(newbie) (2 Replies)
Discussion started by: nikki1200
2 Replies

6. Shell Programming and Scripting

Need help to understand Awk code.

Hi Guys, Can someone please explain this code to me. I could figure out it's adding and comparing two fields but I am not sure which ones. sort -t"|" -k3.1 /tmp/mpcashqc.xtr| awk -F"|" '{CHECKAMT+=$3;BATCHTOT=$4;\ items++}END{for(i in CHECKAMT) if (CHECKAMT!=BATCHTOT)... (6 Replies)
Discussion started by: nua7
6 Replies

7. Shell Programming and Scripting

bash shell: 'exec', 'eval', 'source' - looking for help to understand

Hi, experts. Whould anybody clear explay me difference and usage of these 3 commands (particulary in bash) : exec eval source I've tryed to read the manual pages but did not get much. Also could not get something useful from Google search - just so much and so not exactly, that is... (3 Replies)
Discussion started by: alex_5161
3 Replies

8. UNIX for Advanced & Expert Users

Code Understand ?

Hey, Could you explain me what this code is doing ? For example: $i has value 9 $1 is the name of the file say FILEBkUp while do if $1.`/bin/expr $i - 1` ] then mv -f $1.`/bin/expr $i - 1` $1.$i fi i=`/bin/expr $i - 1` done Thanks... (2 Replies)
Discussion started by: varungupta
2 Replies

9. What is on Your Mind?

dont understand

i'm trying to learn unix and i posted a question and what i was typing from school. i can't figure it out. how am i supposed to learn , when i get shutdown by an admin. for posting a homework question. doesn't make any sense. its a dumb rule. thanks for helping (4 Replies)
Discussion started by: AtomJ22
4 Replies
Login or Register to Ask a Question