I have a 200 point program to write for school that says how much extra grain will be left in the silo and Tomorrow is the last day to turn it in. But something is wrong with my while loop. Could you help me out? Also, I'm writing this code from memory. So bear with me. The A- version of this program is to write a for loop to enter the number of cars. But I don't have enough time to re-write an entire program. seeing as I can only work on the actual program in class.

``````#include <iostream.h>
#include <math.h>
int main (void)
{
float Height, Radius, Height, BoxHeight, BoxLength, BoxWidth, SiloVolume, BoxVolume, BoxVolumesum, Grainleft;
char choice = y
cout << "Enter height of silo." << endl;
cin >> Height;
cout << "Enter the Radius of the silo." << endl;
SiloVolume = 3.14 * pow(Radius, 2) * Height;
BoxVolume = 0
while ( choice == 'y')
{
cout << "Enter Height of box car." << endl;
cin >> BoxHeight;
cout << "Enter length of box car. << endl;
cin >> BoxLength;
cout << "Enter the width of box car. << endl;
cin << BoxWidth;
BoxVolume = BoxHeight*BoxLength*BoxWidth;
cout << "Would you like to add another car? Type y if yes, or any other key for no.";
cin >> Choice;
}
BoxVolumesum = BoxVolume + Boxvolumesum;
Grainleft = SiloVolume - BoxVolumesum;
cout << "You will have" <<Grainleft<< "grain left." << endl;
return (0);
}``````

I didn't notice an if statement.....It could be said that was the only thing that didn't have any errors...What compiler are you using?

``````#include <iostream>
#include <cmath>

using namespace std;

int main (void)
{
float Height, Radius, BoxHeight, BoxLength, BoxWidth, SiloVolume, BoxVolume, BoxVolumesum = 0, Grainleft;
char choice = 'y';

cout << "Enter height of silo." << endl;
cin >> Height;
cout << "Enter the Radius of the silo." << endl;

SiloVolume = 3.14 * pow(Radius, 2) * Height;
BoxVolume = 0;

while ( choice == 'y')
{
cout << "Enter Height of box car." << endl;
cin >> BoxHeight;
cout << "Enter length of box car." << endl;
cin >> BoxLength;
cout << "Enter the width of box car." << endl;
cin >> BoxWidth;

BoxVolume = BoxHeight * BoxLength * BoxWidth;

cout << "Would you like to add another car? Type y if yes, or any other key for no.";
cin >> choice;
}

BoxVolumesum = BoxVolume + BoxVolumesum;
Grainleft = SiloVolume - BoxVolumesum;
cout << "You will have " <<Grainleft<< " grain left." << endl;

return (0);
}``````

For future reference...Please adopt a neater coding/posting scheme, something like the above code.

Be a part of the DaniWeb community

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