Just testing out arrays on this one. MY project is to create a thermometer that converts Celsius to Fahrenheit or vice-versa.

#include <iostream>
#include <windows.h>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
	cout << setiosflags(ios::fixed) << setprecision(2) << ios::showpoint;
	float value1[11], value2[11];
	char gauge1, gauge2, gauge;
	cout << "Welcome to my program, which converts celsius into fahrenheit,\nor fahrenheit into celsius.\n\n";
	cout << "**********\nCelsius - c\n**********\n\n";
	cout << "**********\nfahrenheit - f\n**********\n\n";
	cout << "Please enter the gauge that you would like to convert: ";
	cin >> gauge;
	system("cls");
	cout << "Please enter the temperature that you would like to see converted(1-999): ";
	cin >> value1[6]; 
	if(gauge == 'c')
	{
		gauge1 = 'C';
		gauge2 = 'F';
		value1[5] = value1[6] + 1;
		value1[4] = value1[5] + 1;
		value1[3] = value1[4] + 1;
		value1[2] = value1[3] + 1;
		value1[1] = value1[2] + 1;
		value1[7] = value1[6] - 1;
		value1[8] = value1[7] - 1;
		value1[9] = value1[8] - 1;
		value1[10] = value1[9] - 1;
		value1[11] = value1[10] - 1;


		value2[1]=value1[1]*(9/5)+32;
		value2[11]=value1[11]*(9/5)+32;
		value2[10]=value1[10]*(9/5)+32;
		value2[9]=value1[9]*(9/5)+32;
		value2[8]=value1[8]*(9/5)+32;
		value2[7]=value1[7]*(9/5)+32;
		value2[6]=value1[6]*(9/5)+32;
		value2[5]=value1[5]*(9/5)+32;
		value2[4]=value1[4]*(9/5)+32;
		value2[3]=value1[3]*(9/5)+32;
		value2[2]=value1[2]*(9/5)+32;


	}
	else
	{
		gauge1 = 'F';
		gauge2 = 'C';
		value2[6]=value1[6]*(9/5)+32;
	}
	system("cls");
	cout << setw(32) << gauge1 << " |          | " << gauge2 << endl; 
	cout << setw(45) <<            "|          |" << endl; 
	cout << setw(32) << value1[1] << "-|          |-" << value2[1] << endl; 
	cout << setw(32) << value1[2] << "-|          |-" << value2[2] << endl; 
	cout << setw(32) << value1[3] << "-|          |-" << value2[3] << endl; 
	cout << setw(32) << value1[4] << "-|          |-" << value2[4] << endl; 
	cout << setw(32) << value1[5] << "-|          |-" << value2[5] << endl; 
	cout << setw(32) << value1[6] << "-|**********|-" << value2[6] << endl; 
	cout << setw(32) << value1[7] << "-|**********|-" << value2[7] << endl; 
	cout << setw(32) << value1[8] << "-|**********|-" << value2[8] << endl; 
	cout << setw(32) << value1[9] << "-|**********|-" << value2[9] << endl; 
	cout << setw(32) << value1[10] << "-|**********|-" << value2[10] << endl; 
	cout << setw(32) << value1[11] << "-|**********|-" << value2[11] << endl; 
	cout << setw(45) <<            "|**********|" << endl; 
	cout << setw(46) <<           "/************\\" << endl; 
	cout << setw(47) <<          "/**************\\" << endl; 
	cout << setw(48) <<         "|****************|" << endl; 
	cout << setw(48) <<         "|****************|" << endl; 
	cout << setw(48) <<         "|****************|" << endl; 
	cout << setw(48) <<         "|****************|" << endl; 
	cout << setw(48) <<         "|****************|" << endl; 
	cout << setw(47) <<         "\\**************/" << endl; 
	cout << setw(46) <<          "\\************/" << endl; 




}

By using "float value1[11]" you create an array of 11 elements, which starts from value1[0] and ends at value1[10]. So value1[11] is not in the array.

Ahh, thank you for the help. However the code is still wrong. The equations:

value2[1]=value1[1]*(9/5)+32;
		value2[11]=value1[11]*(9/5)+32;
		value2[10]=value1[10]*(9/5)+32;
		value2[9]=value1[9]*(9/5)+32;
		value2[8]=value1[8]*(9/5)+32;
		value2[7]=value1[7]*(9/5)+32;
		value2[6]=value1[6]*(9/5)+32;
		value2[5]=value1[5]*(9/5)+32;
		value2[4]=value1[4]*(9/5)+32;
		value2[3]=value1[3]*(9/5)+32;
		value2[2]=value1[2]*(9/5)+32;

are being skipped when calculating Celsius. *I am not working on Fahrenheit atm.*

Edited 7 Years Ago by restrictment: n/a

Ahh, thank you for the help. However the code is still wrong. The equations:

value2[1]=value1[1]*(9/5)+32;
		value2[11]=value1[11]*(9/5)+32;
		value2[10]=value1[10]*(9/5)+32;
		value2[9]=value1[9]*(9/5)+32;
		value2[8]=value1[8]*(9/5)+32;
		value2[7]=value1[7]*(9/5)+32;
		value2[6]=value1[6]*(9/5)+32;
		value2[5]=value1[5]*(9/5)+32;
		value2[4]=value1[4]*(9/5)+32;
		value2[3]=value1[3]*(9/5)+32;
		value2[2]=value1[2]*(9/5)+32;

are being skipped when calculating Celsius. *I am not working on Fahrenheit atm.*

These lines are not being skipped. The Fahrenheit values are 32 larger than the Celsius values, which suggests that at least part of the equation is working. Comment the lines out and pick a different Celsius value than you did the last time you ran the program and see what results you get. You'll see that those lines DO have results.

What is being "skipped" is the (9/5) part. 9 / 5 equals 1. Anything times 1 is itself. Hence that part was "skipped" ("skipped" is in quotes because it wasn't skipped; it was evaluated and had no effect.

9 / 5 is 1, not 1.8. 9.0 / 5 is 1.8. It has to do with typecasting and integer division.

http://cnx.org/content/m18717/latest/

Change your line to this and see if you get better results:

value2[1]=value1[1]*(9.0/5)+32;

Do the same for the other lines like this.

Edited 7 Years Ago by VernonDozier: n/a

These lines are not being skipped. The Fahrenheit values are 32 larger than the Celsius values, which suggests that at least part of the equation is working. Comment the lines out and pick a different Celsius value than you did the last time you ran the program and see what results you get. You'll see that those lines DO have results.

What is being "skipped" is the (9/5) part. 9 / 5 equals 1. Anything times 1 is itself. Hence that part was "skipped" ("skipped" is in quotes because it wasn't skipped; it was evaluated and had no effect.

9 / 5 is 1, not 1.8. 9.0 / 5 is 1.8. It has to do with typecasting and integer division.

http://cnx.org/content/m18717/latest/

Change your line to this and see if you get better results:

value2[1]=value1[1]*(9.0/5)+32;

Do the same for the other lines like this.

Thanks, that helped a lot. I finally got it working correctly! =)

This article has been dead for over six months. Start a new discussion instead.