I am having trouble writing my program to an outFile. When I try it only lets my program execute one time, instead of multiple times. I need basic beginners instruction.....Help??!!
switch (option)
{
case 1:
{
cout << "Enter the number of seconds: " << endl;
cin >> time;
while (time < 0 || time > 30)
{
cout << "The number must be between 0 and 30." << endl;
cout << "Enter the number of seconds: " << endl;
cin >> time;
}
car(time, distancemeters, distancemiles, meters_mile);
break;
}
case 2:
{
cout << "Enter the number of seconds: " << endl;
cin >> time;
while (time < 0 || time > 30)
{
cout << "The number must be between 0 and 30.";
cout << "Enter the number of seconds: " << endl;
cin >> time;
}
air(time, distancemeters, distancemiles, meters_mile);
break;
}
case 3:
{
cout << "Enter the number of seconds: " << endl;
cin >> time;
while (time < 0 || time > 30)
{
cout << "The number must be between 0 and 30." << endl;
cout << "Enter the number of seconds: " << endl;
cin >> time;
}
hel(time, distancemeters, distancemiles, meters_mile);
break;
}
case 4:
{
cout << "Enter the number of seconds: " << endl;
cin >> time;
while (time < 0 || time > 30)
{
cout << "The number must be between 0 and 30." << endl;
cout << "Enter the number of seconds: " << endl;
cin >> time;
}
hyd(time, distancemeters, distancemiles, meters_mile);
break;
}
case 5:
break;
default:
cout << "You must select 1, 2, 3, or 4!" << endl;
break;
}
}
while (option != 5);
cout << "That's All Folks...." << endl;
cout << "The distance traveled in Air is " << distancemeters << " meters or " << distancemiles << " miles.\n" << endl;
if (distancemiles < 1)
cout << "The sound source is very close!\n" << endl;
else if (distancemiles < 15)
cout << "The sound source is moderately close!\n" << endl;
}
void hel(double time, double distancemeters, double distancemiles, double meters_mile)
{
const double heliumspeed = 972.0;
distancemeters = heliumspeed * time;
distancemiles = distancemeters / meters_mile;
cout << "The distance traveled in Helium is " << distancemeters << " meters or " << distancemiles << " miles.\n" << endl;
if (distancemiles < 1)
cout << "The sound source is very close!\n" << endl;
else if (distancemiles < 15)
cout << "The sound sorce is moderately close!\n" << endl;
}
void hyd(double time, double distancemeters, double distancemiles, double meters_mile)
cout << "The distance traveled in Hydrogen is " << distancemeters << " meters or " << distancemiles << " miles.\n" << endl;
if (distancemiles < 1)
cout << "The sound source is very close!\n" << endl;
else if (distancemiles < 15)
cout << "The sound source is moderately close!\n" << endl;
}
Ok. However, you haven't explained what information you want to be put into the output file, and under what circumstances. In order to provide any useful help you need to be clearer about what it is you want the program to achieve.
The original post offered this detail:
When I try it only lets my program execute one time, instead of multiple times.
that suggests the actual problem was getting the while-loop to behave correctly.
To be fair, I guess I was distracted by the code which was posted. If the question had been asked with no accompanying code at all, then a good starting point would be this section of the tutorial pages: http://www.cplusplus.com/doc/tutorial/files/
Of course, putting theory into practice isn't always trouble-free. I suggest you combine some of the ideas from that tutorial with some of your existing code, put them together and if you have problems, post the code showing how far you got - and describing any problems there are.
When you run this program, ALL of the results which execute correctly on the console needs to be written out. So to make it simple for every cout to console it needs to be written to an output file. I would put it in the code but i do not understand how. My professor does not want a screen shot he wants the results put in to an output file and printed to be turned in. Ex: when I chose 1-5 as prompted it executes correctly on console, but when I add output commands under my couts it will only execute 1 choice and my professor wants to see them ALL execute on my output file.