warning: multi-character character constant error

Joined
Jan 15, 2011
Messages
4
Reaction score
0
Hi, I'm new to this forum and I'm just starting off using C++. Anyway here is the problem: I'm trying to make a program that does chemistry calculations for me. Here is the code:

#include <iostream>
using namespace std;
int main ()
{
char chem_reply;
cout << "Type in 'f' for frequency, 'w' for wavelength, and 'e' for energy: ";
cin >> chem_reply;
switch (chem_reply)
{
case 'f':
case 'F':
{
long double c = 3.00e+8;
long double wavelength;
long double frequency;
cout << "Enter wavelength: ";
cin >> wavelength;
frequency = c/wavelength;
cout << "The frequency is *" << frequency << "*.";
}
break;
case 'w':
case 'W':
{
long double c= 3.00e+8;
long double frequency;
long double wavelength;
cout << "Enter frequency: ";
cin >> frequency;
wavelength = c/frequency;
cout << "The wavlength is *" << wavelength << "*.";
}
break;

case 'e':
case 'E':
char reply;
cout << "Is the frequency given?: ";
cin >> reply;
if (reply== 'yes' || reply=='Yes')
{
long double h= 6.626e-34;
long double energy;
long double frequency;
cout << "Enter frequency: ";
cin >> frequency;
energy = h*frequency;
cout<< "The energy of the wave is *" << energy << "*";
}
if (reply == 'no' || reply == 'No')
{
long double h= 6.626e-34;
long double c= 3.00e+8;
long double wavelength;
long double energy;
cout << "Enter wavelength: ";
cin >> wavelength;
energy = (h*c)/wavelength;
cout << "The energy of the wave is *" << energy << "*";
}
break;
}
}

The problem is when i ask it to do an energy calculation which, as you can see, has 'if' statements in it. The program doesn't go any further than asking me to type in whether I am give the frequency. After I type it, the code just simply ends.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top