Announcement

Collapse
No announcement yet.

uni help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    uni help

    i know this is real cheecky but it is real driving me crazy heres the problem
    in uni today got real stuck and iam still stuck has can not use the code at home due to it not working in bloodshed (because not used to it more than likey)

    heres the code {C++ code)
    void main(){
    int valu;

    cout<<"what number times by 7";
    cin>>valu;

    for (int count=1; count<=12; count++)

    {
    cout<<"7"<<"x"<<valu<<"="<<count*valu<<endl;
    }
    }

    the aim of the code is to wirte a program which outputs one of the multiplication table and loop it 12 times

    the code i have they is for 7 times table but it keeps doing it for 1 x table
    Last edited by DUKENUKEM2UK; 12-10-2005, 14:42.

    #2
    Try the PC forum.

    Comment


      #3
      I'm no programmer, but it looks like there are only strings in there relating to the 7 times table. The output will be count*valu where valu is the cin (which I guess means the user input).

      Can you debug by adding
      cout<<valu;
      before the for loop?

      But I don't know my arse from my elbow, so don't listen to me.

      Comment


        #4
        I'm not sure what you want this program to do. Can you provide more information please?

        The reason it currently prints out the one times table is becuase you are multiplying 'count*valu'. Count increments from 1 to 12 through the for loop but valu remains constant to whatever the user entered.

        To print the 7 times table 'count*valu' should change to '7*count'.


        -weresheep

        Comment


          #5
          Or it should be like this:

          void main(){
          int valu;

          cout<<"what number would you like to multiply?";
          cin>>valu;

          for (int count=1; count<=12; count++)
          {
          cout<<count<<"x"<<valu<<"="<<count*valu<<endl;
          }
          }

          Comment


            #6
            void main()
            {
            int nValu;

            cout<<"The multiplication table for which number?";
            cin>>nValu;

            cout<<"About to show the multiplication table for"<<nValu<<"up to 12*"<<nValu;

            for (int i=1; count<13; ++i)
            {
            cout<<nValu<<"*"<<i<<"="<<nValu*i<<endl;
            }
            }


            PS Learn indentation and code commenting now, or when it comes to writing real code you'll look back at your 10K lines of code in search of a bug and weep.

            Comment


              #7
              D'oh - didn't see Nijo's post there...

              Comment


                #8
                Thanks for all the help will try all the solutions in uni tommrow as i do not have borland C++ 5.02

                Comment


                  #9
                  Seconded about the commenting and indentation.

                  Also, perhaps I'm being picky, but main function should be declared with an int return type. Most (probably all) compilers will allow a void return type but processes should return a value to the system (indicating success or error) when they exit e.g.

                  Code:
                   int main(void) {
                     /* Do stuff. */
                   
                     /* Successful exit. */
                     return 0;
                   }
                  Good luck with your course.

                  -weresheep

                  Comment


                    #10
                    you don't even need the return 0 in int main()

                    so you could not worry about return at all as on exit its naturally assumes return is 0 anyway

                    Comment


                      #11
                      eh?!? if you don't 'return' it won't even compile!

                      What kind of monkey language are you referring to?

                      ;-)

                      Comment


                        #12
                        trust my friend

                        you can ignore it, for visual c++ 2003 anyway, it presumes the return type is 0

                        Comment


                          #13
                          Bloody hell... That is _terrible_

                          Progress, eh?

                          Comment


                            #14
                            you don't even need the return 0 in int main()
                            Yes you do. It's not ANSI C++ otherwise.

                            Comment


                              #15
                              doing another hand out and guess what iam stuck again

                              heres the problem the code below is to allow user to enter tow numbers and the program shows which is the largest number

                              #include <iostream.h>
                              void main(){
                              int a,b;
                              cout<<"Enter a number";
                              cin>>a;
                              cout<<"Another";
                              cin>>b;
                              if (a==b)
                              cout<<"Number are equal";
                              else
                              if (a>b)
                              cout<<"The larger is "<<a<<endl;
                              else
                              cout<<"The larger is "<<b<<endl;

                              i have tryed just adding a new c on to int aslo a cout and in and one in the if but it does not work any advice

                              Comment

                              Working...
                              X