Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void controller();
- float ctof(float);
- float ftoc(float);
- int main()
- {
- controller();
- return 0;
- }
- void controller()
- {
- char yesno = 'n';
- float temperature[10];
- cout << "Would you like to convert Celsius to Fahrenheit(y/n): ";
- while(yesno != 'y' || yesno != 'n')
- {
- cin >> yesno;
- if(yesno == 'y') { // If yes then convert to fahrenheit
- cout << "Celsius to fahrenheit it is then!\n\n";
- break;
- }
- else if(yesno == 'n') {
- cout << "OK! Fahrenheit to Celsius then.\n\n";
- break;
- }
- else cout << "Invalid input, enter either y or n.";
- }
- for(int i = 0; i < 10; i++)
- {
- cout << "Please enter temperature number " << i+1 << ": ";
- cin >> temperature[i];
- }
- cout << endl << "Now for the conversion..."<< endl;
- for(int i = 0; i < 10; i++)
- {
- float temp;
- if(yesno == 'y')
- temp = ctof(temperature[i]);
- else temp = ftoc(temperature[i]);
- cout << "Temperature " << i+1 << ": " << temp << endl;
- }
- }
- float ctof(float cels)
- {
- return (cels/5)*9+32; // The celsius to fahrenheit formula
- }
- float ftoc(float fah)
- {
- return (fah-32)/9*5; // The fahrenheit to celsius formula
- }
Add Comment
Please, Sign In to add comment