Ok so here is my code for a practice homework at LiduidEmberS

#include <iostream>
using namespace std;
int main(void)
{
    int a;
    int b;
    int c;
    int d;
    int radius;
    int volumeprism;
    volumeprism = b*c*d;
    int volumesphere = 1.3333333333333*3.1415926536*(radius^3);


    cout << "Welcome to the program!\n\n";
    cout << "Do you want the volume of:\n";
    cout << "1. Cube\n";
    cout << "2. Sphere\n";
    cout << "3. Exit\n";
    cin >> a;
    switch (a)
    {
    case 1:
        cout<<"enter length";
        cin >> b;
        cout<<"enter height";
        cin >> c;
        cout<<"enter width";
        cin >> d;
        cout << volumeprism;
    break;

    case 2:
        cout << "enter radius";
        cin >> radius;
        cout << volumesphere;
    break;

    case 3:
        return 0;
    break;
    }
    
    return 0;
}

...
I always get the following Warnings:
c:\documents and settings\family\my documents\visual studio 2005\projects\homework1volume\homework1volume\the code.cpp(12) : warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
c:\documents and settings\family\my documents\visual studio 2005\projects\homework1volume\homework1volume\the code.cpp(11) : warning C4700: uninitialized local variable 'b' used
c:\documents and settings\family\my documents\visual studio 2005\projects\homework1volume\homework1volume\the code.cpp(11) : warning C4700: uninitialized local variable 'c' used
c:\documents and settings\family\my documents\visual studio 2005\projects\homework1volume\homework1volume\the code.cpp(11) : warning C4700: uninitialized local variable 'd' used
c:\documents and settings\family\my documents\visual studio 2005\projects\homework1volume\homework1volume\the code.cpp(12) : warning C4700: uninitialized local variable 'radius' used
So by now i KNOW that its something wrong with the variables and the math....
Please help me fix this problem..!

Recommended Answers

All 7 Replies

you did not initialize a, b, c, d, and radius. Get the input than assign.

first of all, the first warning (the one that says about double and int) means that you are initializin an integer (whole number) with values of a double number (a number with decimal points and extreme accuracy)... so, you should initialize your variable as a float or double...

yup, you should give values to a,b, c and radius before using them in a mathematic operation...

int a;//you
int b;//are
int c;//not
int radius;//giving any values to these variables
int volumeprism;
volumeprism=a*b*c; //so when you use them here, 
//it will give you random numbers,
//or what we call junk

got it?

Umm...not really, explain lol

ok... look...

when you initialize a variable with no values, this variables has a random value stored in it. in your program, you assign values to your variables until the end, where you have your switch...

what you have to do is the following:

#include <iostream>
using namespace std;
int main(void)
{
    int a,b,c,d,radius,volumeprism;//see how you can declare
                                   //several variables at the
                                   //same time
    double volumesphere;//volumesphere must be declared as a
                        //double so it returns decimal values

    cout << "Welcome to the program!\n\n";
    cout << "Do you want the volume of:\n";
    cout << "1. Cube\n";
    cout << "2. Sphere\n";
    cout << "3. Exit\n";
    cin >> a;
    switch (a)
    {
    case 1:
        cout<<"enter length";
        cin >> b;
        cout<<"enter height";
        cin >> c;
        cout<<"enter width";
        cin >> d;
        volumeprism=b*c*d;//the math operation you had @ the
                          //beginning goes here so it multiplies
                          //the values you want it to multiply
        cout << volumeprism;
    break;

    case 2:
        cout << "enter radius";
        cin >> radius;
        volumesphere=1.333333333333*3.1415926536*(radius^3);

        //here's the other math operation you had up there

        cout << volumesphere;
    break;

    case 3:
        return 0;
    break;
    }
    
    return 0;
}

and that should do the trick...

the problem is you thought a mathematical operation done in a variable would be done every time you gave different values to variables...

well... that doesn't happen in c++ (or even any other languages)...

Ahh..
ur a good explainer u know?

thank you very much...

solving problems @ daniweb has made me improve my explaining abilities... :D

remember marking your thread as solved if your problem was solved...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.