| | |
temperature help
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Feb 2006
Posts: 23
Reputation:
Solved Threads: 1
can someone help me i can't seem to find my temperature problem
C++ Syntax (Toggle Plain Text)
/**************************** * functions *****************************/ float c2F(float); float f2C(float); /**************************** * gloabal variables *****************************/ int main () { float inTemp; float newTemp; char inCode; cout << "please enter the code (a 'C' of 'F'): "; cin >> inCode; cout << "please enter the tempature to be converted: "; cin >> inTemp; if (inCode == 'C') { newTemp = c2F(inTemp); cout << "converted temp is " << newTemp << "\n"; } else if (inCode == 'F') { newTemp = f2C(inTemp); cout << "converted temp is " << newTemp << "\n"; } else { newTemp = 0; cout << "bad code entered\n"; } system("pause"); return 0; } /**************************** * converts a temp from F->C using the formula F=5/9(C-32) *****************************/ float f2C (float inTemp) { float newTemp = 5/9* (inTemp-32); return newTemp; } /**************************** * converts a temp from C->F the formula C=9/9(F) +32 *****************************/ float c2F (float inTemp) { float newTemp = 9/5* inTemp+32; return newTemp; }
•
•
Join Date: Feb 2006
Posts: 23
Reputation:
Solved Threads: 1
i updated the my code up there again and like when I run it the answer turns out wrong
C++ Syntax (Toggle Plain Text)
/**************************** * functions *****************************/ float c2F(float); float f2C(float); /**************************** * gloabal variables *****************************/ int main () { float inTemp; float newTemp; char inCode; cout << "please enter the code (a 'C' of 'F'): "; cin >> inCode; cout << "please enter the tempature to be converted: "; cin >> inTemp; if (inCode == 'C') { newTemp = c2F(inTemp); cout << "converted temp is " << newTemp << "\n"; } else if (inCode == 'F') { newTemp = f2C(inTemp); cout << "converted temp is " << newTemp << "\n"; } else { newTemp = 0; cout << "bad code entered\n"; } system("pause"); return 0; } /**************************** * converts a temp from F->C using the formula F=5/9(C-32) *****************************/ float f2C (float inTemp) { float newTemp = 5/9* (inTemp-32); return newTemp; } /**************************** * converts a temp from C->F the formula C=9/9(F) +32 *****************************/ float c2F (float inTemp) { float newTemp = 9/5* inTemp+32; return newTemp; }
With integer math 9/5 is 1 and 5/9 is zero. Try 9.0/5.0 and 5.0/9.0.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- AMD64 3400+ concerned about temperature! (Motherboards, CPUs and RAM)
- critical cpu temperature in ibook (Apple Hardware)
- CPU Temperature (Motherboards, CPUs and RAM)
- CPU temperature control/overheating (Motherboards, CPUs and RAM)
- MAJOR Temperature Sensing problem! (Cases, Fans and Power Supplies)
- Temperature Issue? (Cases, Fans and Power Supplies)
Other Threads in the C++ Forum
- Previous Thread: Problem converting Selection Sort to Class
- Next Thread: list not bring created
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






