Equation printing program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mattmao
    New Member
    • Aug 2007
    • 121

    #31
    Is this your code or where did you get it from?

    I used the gcc compiler to test it and found:

    Code:
    charlie$ gcc test.c
    test.c: In function `main':
    test.c:6: error: `cout' undeclared (first use in this function)
    test.c:6: error: (Each undeclared identifier is reported only once
    test.c:6: error: for each function it appears in.)
    test.c:8: error: `cin' undeclared (first use in this function)
    test.c:15: warning: assignment makes integer from pointer without a cast
    test.c:21: warning: assignment makes integer from pointer without a cast
    test.c:27: warning: assignment makes integer from pointer without a cast
    test.c:33: warning: assignment makes integer from pointer without a cast
    test.c:44:2: warning: no newline at end of file
    Something is missing in your code.

    Comment

    • socondc22
      New Member
      • Sep 2007
      • 67

      #32
      Originally posted by mattmao
      Is this your code or where did you get it from?

      I used the gcc compiler to test it and found:

      Code:
      charlie$ gcc test.c
      test.c: In function `main':
      test.c:6: error: `cout' undeclared (first use in this function)
      test.c:6: error: (Each undeclared identifier is reported only once
      test.c:6: error: for each function it appears in.)
      test.c:8: error: `cin' undeclared (first use in this function)
      test.c:15: warning: assignment makes integer from pointer without a cast
      test.c:21: warning: assignment makes integer from pointer without a cast
      test.c:27: warning: assignment makes integer from pointer without a cast
      test.c:33: warning: assignment makes integer from pointer without a cast
      test.c:44:2: warning: no newline at end of file
      Something is missing in your code.
      I know im missing something i just cant figure out what??

      Comment

      • Benny the Guard
        New Member
        • Jun 2007
        • 92

        #33
        Two things.

        1) Put an extra newline at the end of your code. gcc annoyingly reports this although its not really a problem.

        2) You need some includes here. cout is not part of the C++ language persay but rather part of the iostream package. So just put this at the top of your file:

        #include <iostream>

        Comment

        • socondc22
          New Member
          • Sep 2007
          • 67

          #34
          I really need some help to figure this out which is due tomorrow... so anyone that can help please send something

          Comment

          • socondc22
            New Member
            • Sep 2007
            • 67

            #35
            Originally posted by Benny the Guard
            Two things.

            1) Put an extra newline at the end of your code. gcc annoyingly reports this although its not really a problem.

            2) You need some includes here. cout is not part of the C++ language persay but rather part of the iostream package. So just put this at the top of your file:

            #include <iostream>

            i do have that at the top of my code i just didnt paste it in.... what line do i need to add to the bottom

            Comment

            • Benny the Guard
              New Member
              • Jun 2007
              • 92

              #36
              The bottom is just hit enter one more time.

              As for the other issues you may need:

              using namespace std;

              before the main function

              Comment

              • socondc22
                New Member
                • Sep 2007
                • 67

                #37
                Originally posted by Benny the Guard
                The bottom is just hit enter one more time.

                As for the other issues you may need:

                using namespace std;

                before the main function
                i have that too... let me give u my errors... im using emacs....

                expected primary-expression before "char"
                expected ';' before "char"
                expected identifier before ';' token
                expected identifier before ')' token.... and the continues for three more of them

                Comment

                • socondc22
                  New Member
                  • Sep 2007
                  • 67

                  #38
                  Anyone else with any ideas... i need help!!!

                  Comment

                  • Benny the Guard
                    New Member
                    • Jun 2007
                    • 92

                    #39
                    Oh ok, confused by the other list of errors. Three issues I found when compiling this:

                    1. The symbol 'operator' is reserved and cannot be used as a variable name. So this trips up the code. Just rename it and all the places you use it.

                    2. The operator '=' you use in your if statements are assignment operators not the comparison operator, which is '=='. So the code you have is trying to assign a new value to the variable.

                    3. In your if statments you are comparing a char to a string. The "+" means a string but since your variable is a single character you want '+'

                    Fix these up and the code should compile for you.

                    Comment

                    • socondc22
                      New Member
                      • Sep 2007
                      • 67

                      #40
                      Originally posted by Benny the Guard
                      Oh ok, confused by the other list of errors. Three issues I found when compiling this:

                      1. The symbol 'operator' is reserved and cannot be used as a variable name. So this trips up the code. Just rename it and all the places you use it.

                      2. The operator '=' you use in your if statements are assignment operators not the comparison operator, which is '=='. So the code you have is trying to assign a new value to the variable.

                      3. In your if statments you are comparing a char to a string. The "+" means a string but since your variable is a single character you want '+'

                      Fix these up and the code should compile for you.
                      the last thing i have to ask is that if i want to ask the user whether or not he wants to rerun the program... how do i do that... i just want to have him have to enter like y to run again or any other key to exit...

                      Comment

                      • Benny the Guard
                        New Member
                        • Jun 2007
                        • 92

                        #41
                        You can't rerun the program per day. What you want is to do a loop in your program to rerun the code you have. An example of this would be:

                        char rerun_choice = 'c';

                        Code:
                        while (rerun_choice == 'y')
                          {
                          cout << "continue? ";
                          cin >> rerun_choice;
                          }
                        In this code as long as the user hits y <enter> they will be asked again and again. Any other letter and it exits the loop. Actually the better approach here would be a do while loop. Similar to above but the while part is at the bottom, so it runs once regardless of the check. Lookup in your C manual on how to use, its a nice C feature.

                        Comment

                        • socondc22
                          New Member
                          • Sep 2007
                          • 67

                          #42
                          Originally posted by Benny the Guard
                          You can't rerun the program per day. What you want is to do a loop in your program to rerun the code you have. An example of this would be:

                          char rerun_choice = 'c';

                          Code:
                          while (rerun_choice == 'y')
                            {
                            cout << "continue? ";
                            cin >> rerun_choice;
                            }
                          In this code as long as the user hits y <enter> they will be asked again and again. Any other letter and it exits the loop. Actually the better approach here would be a do while loop. Similar to above but the while part is at the bottom, so it runs once regardless of the check. Lookup in your C manual on how to use, its a nice C feature.
                          the only thing that this did was ask if i wanted to continue... it didnt rerun the whole program... also everytime i try anything other than addition it still adds...

                          Comment

                          • Benny the Guard
                            New Member
                            • Jun 2007
                            • 92

                            #43
                            You need to put you code in this while loop. Anything in the while loop will be executed. So put the while loop around the code you already had.

                            Comment

                            • socondc22
                              New Member
                              • Sep 2007
                              • 67

                              #44
                              Originally posted by Benny the Guard
                              You need to put you code in this while loop. Anything in the while loop will be executed. So put the while loop around the code you already had.
                              i put it in and its exited my program no matter what i put in.

                              Comment

                              • Benny the Guard
                                New Member
                                • Jun 2007
                                • 92

                                #45
                                Post your current code again. I must have missed something.

                                Comment

                                Working...