whats wrong with my code?

+1 danial saufi · November 26, 2014
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

void bucket(){
  cout << "hello" << endl;
}
int bucketLogo( int x , int y , int z){

    int totalLogo = x + y + z;
   return totalLogo;
}
float bucketPerimeter( float L , float H){

    float totalPerimeter = L * H;
   return totalPerimeter;
}
int main()
{
   int a;
   int b;
   int c;
   float D;
   float Z;
   int totalLogo;
   double totalPerimeter;
   bucket();
   cin >>  a;
   cin >>  b;
   cin >>  c;
   bucketLogo(a,b, c);
   cout << "your total is " << totalLogo << endl;
   cout << "Enter the perimeter" << endl;
   cin >> D;
   cin >> Z;
   bucketPerimeter(  D , Z );
   cout << " the perimeter is " << totalPerimeter << endl;



}
when i enter the number, any number it goes out
your total is 1973031266
the perimeter is 5.79013e-120
p.s im a newbie still so don judge me
need some suggestion and explain why it is wrong

Post a Reply

Replies

Oldest  Newest  Rating
+3 Mathias Frits Rørvik · November 26, 2014
fixed your code
#include <iostream>
//#include <string> why do you include string?
//#include <cmath> why are you including cmath?
using namespace std;

void bucket(){
    cout << "hello" << endl;
}
int bucketLogo( int x , int y , int z){

    //you don't actually need to do this: int totalLogo = x + y + z;
    //when you type: int totalLogo inside here
    //you declare a brand new variable called totalLogo

//just do this
    return x + y + z;
}
float bucketPerimeter( float l , float h){

    //same here : float totalPerimeter = L * H;
    return l * h;
}

int main()
{
/*
Just a tip, but calling your variables a,b,c,d,z
can be a bad idea, because they don't give other people
an idea of what that is supposed to be stored in them :)
*/
    int a, b, c;

    float d;
    float z;

    int totalLogo;
    double totalPerimeter;

    bucket(); //prints hello

    cin >> a;
    cin >> b;
    cin >> c;

    totalLogo = bucketLogo(a, b, c); //
    cout << "your total is " << totalLogo << endl;
    cout << "Enter the perimeter" << endl;

    cin >> d;
    cin >> z;

    totalPerimeter = bucketPerimeter(d, z);
    cout << "the perimeter is " << totalPerimeter << endl;

    return 0;
}


I have also added some comments explaining some stuff.
0 Bernard Pyc0d333 Parah · December 9, 2014
if you are gonna use it later, then include it when you need it
0 danial saufi · November 27, 2014
@ Mathias Frits Rørvik
wow thanks. man i still need more practice... umm y does it print out a wierd number..(at the top i said what number it was).. i tried changing the input number but it still comes out the same. and if i include string and cmath, does it affect the program or will the program become heavy? because i included it for future uses
0 danial saufi · November 27, 2014
@ Mathias Frits Rørvik
oh thanks man.. i still need to practice .. umm will the program be heavy or will it ruin the program if i include cmath and string cause i put there for future use.
  • 1

C++

106,942 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator