Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

C++ help me code something very simple? im a beginner

hendyies

Coder
this is for a school project.
Calculate how many laps you will run in the stadium if you have to run for at least 10 minutes and how many meters you have ran. Each lap must enter a different time. The length of the stadium is 400 meters.
i also have to use do {...} while)

can someone help me with this?
 
Welcome hendyies,

Calculating the number of laps if the speed is 2.2m/s and time 600 seconds:
C++:
int stadiumLength = 400;
float speed = 2.2;
int nbSeconds = 10 * 60;

int distanceRunned = speed * nbSeconds;
int nbLaps = distanceRunned / stadiumLength;

Repeating the loop as long as the user does not enter 'n':
C++:
char answer;

do
{
    std::cout << "Quit the program? (y/n): ";
    std::cin >> answer;
}
while(answer != 'n' && answer != 'N');

I can not tell you exactly what to do, you must understand!
 
Last edited:
Welcome hendyies,

Calculating the number of laps if the speed is 2.2m/s and time 600 seconds:
C++:
int stadiumLength = 400;
float speed = 2.2;
int nbSeconds = 10 * 60;

int distanceRunned = speed * nbSeconds;
int nbLaps = distanceRunned / stadiumLength;

Repeating the loop as long as the user does not enter 'n':
C++:
char answer;

do
{
    std::cout << "Quit the program? (y/n): ";
    std::cin >> answer;
}
while(answer != 'n' && answer != 'N');

I can not tell you exactly what to do, you must understand!
i appreaciate the help, ill try to do my best, thank you!
 
C++:
#include <iostream>
using namespace std;
int main() {
  
int stadiumLength = 400;
float speed = 2.2;
int nbSeconds = 10 * 60;
int distanceRunned = speed * nbSeconds;
int nbLaps = distanceRunned / stadiumLength;
int main();
do
{
char answer;
    while(true)
    {
        cout<<"Would you like to perform other calculation?(Y/N)"<<endl;
        cin >> answer;
        if(answer == 'Y'|| answer =='y'){
        return true;
        }else if(answer =='N'||answer =='n'){
        return false;
        }
    }
return 0;
}

while(answer != 'n' && answer != 'N');
}


so im getting an error '' ‘answer’ was not declared in this scope'' i was neglecting asking for help because i think its something really obvious but even after researching the error i couldn't fix it for myself. can you help out? p.s. im extremely new to coding, i barely know what the most basic commands do, so this is probably easy to fix but i just didn't get it.
 
Last edited by a moderator:
Back
Top Bottom