warning: multi-character character constant error

Discussion in 'C Programming' started by emeraldsky23, Jan 15, 2011.

  1. emeraldsky23

    emeraldsky23

    Joined:
    Jan 15, 2011
    Messages:
    4
    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.
     
    emeraldsky23, Jan 15, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christopher M. Lusardi
    Replies:
    1
    Views:
    4,100
  2. mimmo
    Replies:
    4
    Views:
    27,988
  3. hn.ft.pris@gmail.com
    Replies:
    13
    Views:
    12,942
    Kai-Uwe Bux
    Jan 22, 2007
  4. aarklon@gmail.com

    multi-character constant

    aarklon@gmail.com, Nov 21, 2007, in forum: C Programming
    Replies:
    11
    Views:
    2,968
    Willem
    Nov 22, 2007
  5. saurabh29789

    Assign char variable with multi-character constant

    saurabh29789, May 28, 2009, in forum: C Programming
    Replies:
    1
    Views:
    969
    saurabh29789
    May 28, 2009
Loading...

Share This Page