Program help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nomana123
    New Member
    • Oct 2008
    • 7

    Program help

    //Test 2 Question #23
    #include<iostre am>

    using namespace std;
    int main()
    {
    //variables defined here
    float y, a, b, w, x, q, h, g;
    char exit_variable;
    int option;
    cout<<"Please chose a program:\n";
    cout<<"\n1. Y=10+((5*a)/((3*b)-(4*b*b)\n";
    cout<<"\n2. w=(6*x*x*x*x*x)-15\n";
    cout<<"\n3. q=(3/4)(h-(7*g)/6)\n";
    cin>>option;
    switch (option)
    {case (1):
    cout<<"\nEnter value for a ";
    cin>>a;
    cout<<"Enter value for b ";
    cin>>b;
    y=10+(5*a/(3*b))-(4*b*b);
    cout<<"The answer is "<<y;
    cout<<"When substituing into the equation Y=10+((5*";cout <<a;
    cout<<")/((3*";cout<<b;
    cout<<")-(4*";
    cin>>b;
    cout<<"*";
    cin>>b;
    cout<<")";
    break;

    case (2):
    cout<<"Enter value for x";
    cin>>x;
    w=(6*x*x*x*x*x)-15;
    cout<<"The answer is ";cin>>w;
    cout<<"/nWhen substituting into the equation w=(6*";
    cin>>x;
    cout<<"*";cin>> x;
    cout<<"*";
    cin>>x;
    cout<<"*";
    cin>>x;
    cout<<")-15";

    break;

    case (3):
    cout<<"Enter value for h";
    cin>>h;
    q=(3/4)*(h-(7*g)/6);
    cout<<"The answer is";cin>>q;
    cout<<"When substituting into the equation q=(3/4)(";
    cin>>h;cout<<"-(7*";
    cin>>g;
    cout<<")/6)";
    break;
    }

    [/code] cin>>exit_varia ble;

    }

    what needs fixing ? :)
    I got a bit further this time. I don't know what you mean by /code.
    I need the program to calculate the 3 equations and output the answer and output what was inputed.
    for example, it should say answer = #
    and then input for a value was # and input for B value was #
    Last edited by nomana123; Oct 31 '08, 02:27 AM. Reason: Mor changes
  • boxfish
    Recognized Expert Contributor
    • Mar 2008
    • 469

    #2
    What's it supposed to do and what's wrong with it? If you are getting errors, please post them here. Also, please use code tags around your code. Put [CODE] before it and [/CODE] after it so it shows up in a code box and the indentation isn't wrecked. Thanks.

    Comment

    • boxfish
      Recognized Expert Contributor
      • Mar 2008
      • 469

      #3
      You have the parentheses wrong somewhere, and you have a problem with integer division.
      3.0 / 4.0 is 0.75
      3 / 4.0 is 0.75
      3.0 / 4 is 0.75
      but
      3 / 4 is 0. When you divide an integer by another integer, the result is rounded down to a whole number. Don't divide two integers unless you know what you are doing. After you fix these things, I think your program will work.
      Here's how code tags are supposed to be used:
      [CODE]
      int main() {
      // Example code.
      return 0;
      }
      [/CODE]
      And when you post it, it will look like this:
      Code:
      int main() {
          // Example code.
          return 0;
      }
      Hope this helps.

      Comment

      • nomana123
        New Member
        • Oct 2008
        • 7

        #4
        so how do i say 3/4?

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by nomana123
          so how do i say 3/4?
          Did you read box's response above?

          Comment

          • boxfish
            Recognized Expert Contributor
            • Mar 2008
            • 469

            #6
            Why not just use 0.75 in your program?

            Comment

            • nomana123
              New Member
              • Oct 2008
              • 7

              #7
              could we delete this post plz

              Comment

              Working...