I have tried everything I know about fixing "else if" clauses. Can someone provide some direction on what I may have messed up in the "else if" clause or what might have gone array above it?
cout << "Please enter the Fahrenheit temperature(s). ";
cout << "Press ENTER after entering all the numbers you wish to have converted to Celsius." << endl;
cout << endl;
cout << endl;
What error are you getting and what have you tried?
Are you using an IDE that formats your code automatically? (Then you can see the error immediately)
#include <iostream>
#include<iomanip>
usingnamespace std;
int main()
{
//decimal rules
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(1);
//variables
char kay = 'y';
float ctemp, ftemp;
cout << "Please enter the Fahrenheit temperature(s). ";
cout << "Press ENTER after entering all the numbers you wish to have converted to Celsius." << endl;
cout << endl;
cout << endl;
//Beginning of Chart
cout << setw(1) << "Fahrenheit" << setw(20) << "Centigrade" << endl;
while (kay == 'y' || kay == 'Y')
{
while (!(cin >> ftemp))
{
cout << "Please enter a non intiger with only on decimal point." << endl;
cin.clear();
cin.ignore(1000, '\n');
if (ftemp < 10000)
{
ctemp = (ftemp - 32) * 5 / 9;
cout << setw(1) << ftemp << setw(20) << ctemp << endl;
elseif (ftemp >= 10000)
{
ctemp = (ftemp - 32) * 5 / 9;
cout << setw(1) << ftemp << setw(20) << ctemp << endl;
}
system("pause");
}
}
}
There was a } missing before the elseif (ftemp >= 10000)
Also there was one } too many before system("pause");
These things are easy to spot if you format your code properly.
#include <iostream>
#include<iomanip>
usingnamespace std;
int main ( )
{
//decimal rules
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(1);
//variables
char kay = '?';
float ctemp, ftemp;
cout << "Please enter the Fahrenheit temperature(s). ";
cout << "Press ENTER after entering all the numbers you wish to have converted to Celsius." << endl;
//Beginning of Chart
cout << setw(1) << "Fahrenheit" << setw(20) << "Centigrade" << endl;
while(cout << " ---> Continue? <y/n>: " and cin >> kay and toupper(kay) == 'Y')
{
while(cout << "Please enter a temperature: " and cin >> ftemp)
{
cout << "Please enter a non integer with only on decimal point." << endl;
ctemp = (ftemp - 32) * 5/9;
cout << setw(1) << ftemp << setw(20) << ctemp << endl;
}
}
return 0;
}
This is probably beacuse you have the else if statement inside your if block (The if block before elseif is not closed until after else if). The else if statement, thus, has no initial if statement.