Related questions
Concept explainers
So I have this code, and everything runs fine when I'm within the parameters of the input validation. But, I am having two issues with this code. First off, when it asks for the speed limit, it asks twice, and I'm unsure of how to fix that. Secondly, when I enter something outside of the input validation parameters, I get an endless loop error. Any advice as to how to fix these problems? I'm not a c++ expert, I'm rather new at the whole thing, so help would be greatly appreciated
#include <iostream>
#include <string>
float getSpeed(double speedLimit, double speed, double calcSpeed, double overSpeed);
using namespace std;
const int lowSpeed = 20;
const int highSpeed = 70;
int main()
{
double speedLimit, speed, calcSpeed, overSpeed();
{
cout << "Enter the speed limit: " ;
cin >>speedLimit;
}
while (speedLimit <=lowSpeed || speedLimit >= highSpeed)
cout << "ERROR: the speed limit must be between, 20 mph and 70 mph." << endl;
cout << "Enter the speed limit." <<endl;
cin >>speedLimit;
cout << "Enter your speed:"<< endl;
cin >> speed;
calcSpeed = speed - speedLimit;
cout << "You were going " ;
cout <<calcSpeed;
cout <<"mph over the speed limit.";
return 0;}
So here what I understood is, You are trying to check a speed limit is between the two speeds. And if yes, then print the message like "You were going 40mph within the speed limit.", Else print the warning message.
So in the below C++ program I am expecting 3 inputs like Minimum speed limit, Maximum limit And speed. After the input reading, I am comparing the min and max values with the speed and printing the corresponding messages
Step by stepSolved in 3 steps with 3 images
- I am currently coding in C++, using Dev C++ application. I keep getting the error " 'null' was not declared in this scope." The line of code that it is refrencing is " std::srand(std::time(null));". I have no idea what is happening or how to fix it.arrow_forwardI can't get it working, can you post a photo of your code? Maybe I'm foamtting it wrong. I'm not familiar with C++arrow_forwardYou are given the source to an application which crashes when it is run. Afterrunning it ten times in a debugger, you find it never crashes in the same place. The application issingle threaded, and uses only the C standard library. What programming errors could be causingthis crash? How would you test each one?arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education