Announcement

Collapse
No announcement yet.

Anyone know C++?

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

  • Anyone know C++?

    Can you give me a hand with this? I have no clue as to what I'm doing

    Code:
    //Displayes user input
    //Verison 1.
    //Overloaded programmer-defined functions. 
    //One function will have value parameters and a return value. 
    //One function will have reference parameters and a void return.  Use function prototypes. 
    //A while or for loop. 
    //An if..else or switch decision. 
    //No global variables. 
    //Optionally include default parameter(s).
    //MS Visual Studio Academic Edition
    
    #include <iostream>
    using namespace std;
    
    int addition (int a, int b)
    {
      int r;
      r=a+b;
      return (r);
    }
    
    int main ()
    {
      int z;
      z = addition (5,3);
      cout << "The result is " << z;
      return 0;
    }
    
     int FindArea(int length, int width); //function prototype (declaration)
    
     int main()
     {
         int lengthOfYard;
         int widthOfYard;
         int areaOfYard;
    
         std::cout << "\nHow wide in feet is your yard? ";
         std::cin >> widthOfYard;
         std::cout << "\nHow long in feet is your yard? ";
         std::cin >> lengthOfYard;
    
         areaOfYard= FindArea(lengthOfYard,widthOfYard);
    
         std::cout << "\nYour yard is ";
         std::cout << areaOfYard;
         std::cout << " square feet\n\n";
         return 0;
     }
    
     int FindArea(int l, int w) // function definition
     {
          return l * w;
     }
    Why is it called tourist season, if we can't shoot at them?

  • #2
    There are plenty of C++ tutorials on the web if you need to learn it (I've got only a most basic understand of it, from partially porting the Mersenne twister pseudorandom number generator to assembly language for my HP48.)

    Comment


    • #3
      I can help but I don't know what you are trying to do. What's the assignment?
      Gigabyte GA-K8N Ultra 9, Opteron 170 Denmark 2x2Ghz, 2 GB Corsair XMS, Gigabyte 6600, Gentoo Linux
      Motion Computing M1400 -- Tablet PC, Ubuntu Linux

      "if I said you had a beautiful body would you take your pants off and dance around a bit?" --Zapp Brannigan

      Comment


      • #4
        I did c++ for dos some 10 years ago and most of it is gone but the more I look at your code....

        aparantly the program is suposed to compute the area of the "yard" specified in lenght and width.

        Originally posted by GT98 View Post
        Can you give me a hand with this? I have no clue as to what I'm doing

        Code:
        int addition (int a, int b)
        {
          int r;
          r=a+b;
          return (r);
        }
        Uhm... why is the above included?

        Code:
        int main ()
        {
          int z;
          z = addition (5,3);
          cout << "The result is " << z;
          return 0;
        }
        Ant this??

        Code:
         int FindArea(int length, int width); //function prototype (declaration)
        
         int main()
         {
             int lengthOfYard;
             int widthOfYard;
             int areaOfYard;
        
             std::cout << "\nHow wide in feet is your yard? ";
             std::cin >> widthOfYard;
             std::cout << "\nHow long in feet is your yard? ";
             std::cin >> lengthOfYard;
        
             areaOfYard= FindArea(lengthOfYard,widthOfYard);
        
             std::cout << "\nYour yard is ";
             std::cout << areaOfYard;
             std::cout << " square feet\n\n";
             return 0;
         }
        
         int FindArea(int l, int w) // function definition
         {
              return l * w;
         }
        uhm...I can't be sure that they havent included AI in the compailers but try this:

        Code:
        int FindArea(int length, int width); //function prototype (declaration)
        
         int main()
         {
             int l;
             int w;
             int areaOfYard;
        
             std::cout << "\nHow wide in feet is your yard? ";
             std::cin >> w;
             std::cout << "\nHow long in feet is your yard? ";
             std::cin >> l;
        
             areaOfYard= FindArea(int l, int w);
        
             std::cout << "\nYour yard is ";
             std::cout << areaOfYard;
             std::cout << " square feet\n\n";
             return 0;
         }
        
         int FindArea(int l, int w) // function definition
         {
              return l * w;
         }
        not that I'd be surpriced if it still didnt compaile
        If there's artificial intelligence, there's bound to be some artificial stupidity.

        Jeremy Clarkson "806 brake horsepower..and that on that limp wrist faerie liquid the Americans call petrol, if you run it on the more explosive jungle juice we have in Europe you'd be getting 850 brake horsepower..."

        Comment


        • #5
          Technoid, I'm not sure it your code will compile but it will certainly crash or return bogus values:

          Following line "areaOfYard= FindArea(int l, int w);" should be "areaOfYard = FindArea(l, w);" you don't have to specify the data type.
          Last edited by KeiFront; 18 December 2006, 05:28.
          Main: Dual Xeon LV2.4Ghz@3.1Ghz | 3X21" | NVidia 6800 | 2Gb DDR | SCSI
          Second: Dual PIII 1GHz | 21" Monitor | G200MMS + Quadro 2 Pro | 512MB ECC SDRAM | SCSI
          Third: Apple G4 450Mhz | 21" Monitor | Radeon 8500 | 1,5Gb SDRAM | SCSI

          Comment


          • #6
            Sorry about that guys, I was having a bad night last night (broke up with GF and couldn't quite think straight and having this due last night at midnight didnt help)

            Basically what I'm trying to do is have two different fuctions.

            The sq footage fuction works fine, as you can tell. The problem is that I can't get the fix value fuctions to work, I'm not sure how to show these together, ie have the sq footage fuction work, then goto the fix value fuction.

            Here is the fixed value fuction:
            Code:
            int addition (int a, int b)
            {
              int r;
              r=a+b;
              return (r);
            }
            
            int main ()
            {
              int z;
              z = addition (5,3);
              cout << "The result is " << z;
              return 0;
            }
            Here is the sq footage fuction:
            Code:
            int FindArea(int length, int width); //function prototype (declaration)
            
             int main()
             {
                 int lengthOfYard;
                 int widthOfYard;
                 int areaOfYard;
            
                 std::cout << "\nHow wide in feet is your yard? ";
                 std::cin >> widthOfYard;
                 std::cout << "\nHow long in feet is your yard? ";
                 std::cin >> lengthOfYard;
            
                 areaOfYard= FindArea(lengthOfYard,widthOfYard);
            
                 std::cout << "\nYour yard is ";
                 std::cout << areaOfYard;
                 std::cout << " square feet\n\n";
                 return 0;
             }
            
             int FindArea(int l, int w) // function definition
             {
                  return l * w;
             }
            Why is it called tourist season, if we can't shoot at them?

            Comment


            • #7
              You mean something like this?

              Code:
              int FindArea(int length, int width); //function prototype (declaration)
              int addition (int a, int b);
              
              int main()
              {
              	int lengthOfYard;
              	int widthOfYard;
              	int areaOfYard;
              	int z;
              
              	std::cout << "\nHow wide in feet is your yard? ";
              	std::cin >> widthOfYard;
              	std::cout << "\nHow long in feet is your yard? ";
              	std::cin >> lengthOfYard;
              
              	areaOfYard= FindArea(lengthOfYard,widthOfYard);
              	
              	std::cout << "\nYour yard is " << areaOfYard << " square feet\n\n";
              
              	z = addition (5,3);
              	std::cout << "The result is " << z;
              	return 0;
              }
              
              int addition (int a, int b)
              {
              	return (a + b);
              }
              int FindArea(int l, int w) // function definition
              {
              	return (l * w);
              }
              Main: Dual Xeon LV2.4Ghz@3.1Ghz | 3X21" | NVidia 6800 | 2Gb DDR | SCSI
              Second: Dual PIII 1GHz | 21" Monitor | G200MMS + Quadro 2 Pro | 512MB ECC SDRAM | SCSI
              Third: Apple G4 450Mhz | 21" Monitor | Radeon 8500 | 1,5Gb SDRAM | SCSI

              Comment


              • #8
                Originally posted by KeiFront View Post
                Technoid, I'm not sure it your code will compile but it will certainly crash or return bogus values:

                Following line "areaOfYard= FindArea(int l, int w);" should be "areaOfYard = FindArea(l, w);" you don't have to specify the data type.
                Oki
                If there's artificial intelligence, there's bound to be some artificial stupidity.

                Jeremy Clarkson "806 brake horsepower..and that on that limp wrist faerie liquid the Americans call petrol, if you run it on the more explosive jungle juice we have in Europe you'd be getting 850 brake horsepower..."

                Comment


                • #9
                  You do realize you have two Mains, right?

                  Or are these seperate files?

                  I'm still not clear on what you want to happen.

                  Comment

                  Working...
                  X