Results 1 to 8 of 8
  1. #1
    yair's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Posts
    50
    Reputation
    10
    Thanks
    1

    Project 3 [Solved]

    so i sort of got the hang of c++ but i still havent been able to finish the project... heres what i have so far but keeps giving me errors..anything that u guys can teach would be greatly apreciated

    //Yair Jimenez

    #include <iostream>
    using namespace std;

    int main
    {
    int double length=0,width=0,volume=0,maxvolume=0,height=0,max height=0;cut;

    cout << "\nEnter Length in cm: "<<endl;
    char again = 'y';
    while (again=='y'||again=='Y')
    while (!(cin >> length)||length <=0)
    {
    cout << "\nEnter length"<<endl;
    while (!(cin>>length)||length <=0)
    {
    cout << "\nError,invalid entry.Re-Enter length in cm (must be positive integer): "<<endl;
    cin.clear();
    fflush(stdin);
    }
    cout <<"\nEnter width: "<<endl;
    while(!(cin >> width)||width <=0)
    {
    cout <<"\nError, invalid entry .Re-Enter Length in cm (must be positive integer): "<<endl;
    cin.clear();
    fflush(stdin);
    }

    for (heigh=0;height<(length/2);height+=0.001)
    {
    Volume = (length-(2*height)) * (width-(2 * height)) * (height);
    if (maxvolume < volume
    {maxvolume=volume
    cut=height
    }
    {
    cout <<"\n with length of"<<length<<"cm"
    <<"and width of"<<width
    <<"cm: "<<endl;
    cout <<"\nResult of maximum volume is: "
    <<maxvolume<<",and the cut is: "<<cut<<endl;
    fflush(stdin);
    cout<<endl<<" press y to start over, other press enter to exit";
    cin>>again
    }
    }
    }
    }

  2. #2
    Alcazer's Avatar
    Join Date
    Sep 2011
    Gender
    male
    Posts
    20
    Reputation
    10
    Thanks
    2
    Quote Originally Posted by yair View Post
    so i sort of got the hang of c++ but i still havent been able to finish the project... heres what i have so far but keeps giving me errors..anything that u guys can teach would be greatly apreciated

    //Yair Jimenez

    #include <iostream>
    using namespace std;

    int main
    {
    int double length=0,width=0,volume=0,maxvolume=0,height=0,max height=0;cut;

    cout << "\nEnter Length in cm: "<<endl;
    char again = 'y';
    while (again=='y'||again=='Y')
    while (!(cin >> length)||length <=0)
    {
    cout << "\nEnter length"<<endl;
    while (!(cin>>length)||length <=0)
    {
    cout << "\nError,invalid entry.Re-Enter length in cm (must be positive integer): "<<endl;
    cin.clear();
    fflush(stdin);
    }
    cout <<"\nEnter width: "<<endl;
    while(!(cin >> width)||width <=0)
    {
    cout <<"\nError, invalid entry .Re-Enter Length in cm (must be positive integer): "<<endl;
    cin.clear();
    fflush(stdin);
    }

    for (heigh=0;height<(length/2);height+=0.001)
    {
    Volume = (length-(2*height)) * (width-(2 * height)) * (height);
    if (maxvolume < volume
    {maxvolume=volume
    cut=height
    }
    {
    cout <<"\n with length of"<<length<<"cm"
    <<"and width of"<<width
    <<"cm: "<<endl;
    cout <<"\nResult of maximum volume is: "
    <<maxvolume<<",and the cut is: "<<cut<<endl;
    fflush(stdin);
    cout<<endl<<" press y to start over, other press enter to exit";
    cin>>again
    }
    }
    }
    }
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	int length=0,width=0,cut;
    	double volume=0,maxvolume=0,height=0,maxheight=0;	
    	char again = 'y';
    	while (again=='y'||again=='Y')
    	{
    		cout << "\nEnter Length in cm: "<<endl;
    		cin >> length;
    		while (length <=0)
    		{
    			cout << "\nError,invalid entry.Re-Enter length in cm (must be positive integer): "<<endl;
    			cin.clear();
    			fflush(stdin);
    			cout << "\nEnter length"<<endl;
    			cin>>length;	
            	}
    
    		cout <<"\nEnter width: "<<endl;
    		cin >> width;
    		while(width <=0)
    		{
    			cout <<"\nError, invalid entry .Re-Enter Length in cm (must be positive integer): "<<endl;
    			cin.clear();
    			fflush(stdin);
    			cout <<"\nEnter width: "<<endl;
    			cin >> width;
    		}
    			
    		for (height=0;height<(length/2);height+=0.001)
    		{
    			volume = (length-(2*height)) * (width-(2 * height)) * (height);
    			if (maxvolume < volume)
    				maxvolume=volume;
    			cut=height;
    		}
    		
    		cout <<"\n with length of "<<length<<"cm"<<" and width of "<<width<<"cm"<<endl;
    		cout <<"\nResult of maximum volume is: "<<maxvolume<<",and the cut is: "<<cut<<endl;
    		fflush(stdin);
    		cout<<endl<<" press y and enter to start over, other press enter to exit"<<endl;
    		cin>>again;
    	}
    	return 0;
    }
    Last edited by Alcazer; 09-21-2011 at 09:06 PM.

  3. The Following User Says Thank You to Alcazer For This Useful Post:

    Hell_Demon (09-22-2011)

  4. #3
    yair's Avatar
    Join Date
    Aug 2009
    Gender
    male
    Posts
    50
    Reputation
    10
    Thanks
    1
    when i enter 10 and 20 i should get a cut of 2.11 and max volume of 192.45...do u know what im doing wrong?

  5. #4
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    You're using integers for width and height, change those to doubles. integers don't allow decimals
    Ah we-a blaze the fyah, make it bun dem!

  6. #5
    Ryuesi's Avatar
    Join Date
    Jun 2011
    Gender
    male
    Location
    Right here.
    Posts
    7,339
    Reputation
    413
    Thanks
    2,397
    My Mood
    Relaxed
    Quote Originally Posted by Hell_Demon View Post
    You're using integers for width and height, change those to doubles. integers don't allow decimals
    Correct





    Contributor Since 24-11-2011 ~ 26-12-2011
    VM / PM




  7. #6
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    /Marking solved. Jason helped him fix the code.

    Here's the fixed code:
    [highlight=vb]//Yair Jimenez

    #include <iostream>
    using namespace std;

    int main()
    {
    int length=0, width=0; //givin value to different variables
    char again = 'y';
    while (again=='y'||again=='Y') // allows the user to run the program multiple times
    {
    cout << "\nEnter the Length: "<<endl; //tells the user to enter the length
    cin >> length;
    while (length <=0)
    {

    cout << "\nError,invalid entry.Re-Enter length (must be positive integer): "<<endl; //Displays error message if the width is not a postive integer
    cin.clear(); fflush(stdin);
    cout << "\nEnter length"<<endl;
    cin>>length; //holds the integer entered for length
    }

    cout <<"\nEnter width: "<<endl;
    cin >> width; //holds the integer entered for width

    while(width <=0)
    {
    cout <<"\nError, invalid entry .Re-Enter Length (must be positive integer): "<<endl; //Displays error message if the width is not a postive integer
    cin.clear();fflush(stdin);
    cout <<"\nEnter width: "<<endl;
    cin >> width;
    }

    double cut = 0, volume = 0, curvolume = 0;
    double upperBound = length / 2.0;
    if ( width / 2.0 < upperBound ) upperBound = width / 2.0;

    for(cut = 0.0; cut < upperBound; cut += 0.01)
    {
    curvolume = (length - ( cut * 2 )) * (width - ( cut * 2 )) * cut;
    if ( volume > curvolume )
    break;
    volume = curvolume;
    }
    cut -= 0.01;

    cout <<"\n For the entered sides of length "<<length<<" and width of "<<width<<endl; //displays information
    cout <<"\nResult of maximum volume is: "<<volume<<",and the cut is: "<<cut<<endl;
    fflush(stdin);
    cout<<endl<<" Do you want to run the program again <y/n>?"<<endl; //ask user if they would like to run the program again
    cin>>again;

    }
    return 0;
    }[/highlight]
    Last edited by Hassan; 09-22-2011 at 11:52 AM.

  8. The Following User Says Thank You to Hassan For This Useful Post:

    Alcazer (09-22-2011)

  9. #7
    iEx's Avatar
    Join Date
    Sep 2011
    Gender
    male
    Location
    Wisconsin
    Posts
    113
    Reputation
    10
    Thanks
    6
    My Mood
    Doh
    I just tried that code, works great at finding the volume

  10. #8
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by Hell_Demon View Post
    You're using integers for width and height, change those to doubles. integers don't allow decimals
    It was actually that he was storing cut in an integer, as well as doing some weirdo thing for the loop rofl.

    Code still looks ugly as dick.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

Similar Threads

  1. [Solved] CAFlames and other hacks won't work... Solved
    By Hikatso in forum Combat Arms Help
    Replies: 17
    Last Post: 04-28-2011, 10:41 PM
  2. [Help]Finding .exe of my project [solved]
    By MrSni in forum Visual Basic Programming
    Replies: 5
    Last Post: 04-14-2011, 09:08 PM
  3. [HELP] Project to Exe [solved]
    By -=Coffee=- in forum Visual Basic Programming
    Replies: 5
    Last Post: 04-05-2011, 12:45 PM
  4. [Help]My Project[Solved]
    By docoon in forum Visual Basic Programming
    Replies: 3
    Last Post: 09-28-2010, 11:11 AM
  5. [Help]Project as .Rar[Solved]
    By tremaster in forum Visual Basic Programming
    Replies: 5
    Last Post: 03-27-2010, 12:33 PM