Help creating a do-while loop.
I need help starting a do-while loop in my program that runs up to 10 time that asks the user to enter up to 10 scores, which include the slope and rating for the course, and calculates the handicap for each score. Any help is greatly appreciated. Here's what I have so far:
//This program calculates a golfers handicap.
#include <iostream>
#include <string>
using namespace std;
int main()
{
int score, slope;
double rating, handicap;
string name;
cout << "This program calculates a golfer's handicap.\n";
//Have the user to input their name, score, slope, and handicap.
cout << "Enter your name: ";
cin >> name;
cout << "Hello " << name << endl;
cout << "Please enter your score: ";
cin >> score;
cout << "Please enter the course slope: ";
cin >> slope;
cout << "Please enter the course rating: ";
cin >> rating;
//Calculate the golfers handicap
handicap = (score-rating) * 113 / slope ;
cout << "Your handicap is " << handicap << endl;
return 0;
}
Re: Help creating a do-while loop.
Re: Help creating a do-while loop.
When postimg code, please use code tags. Go Advanced, select the code and click '#'.
Quote:
up to 10 time that asks the user to enter up to 10 scores,
What is meant by 'up to 10'. How will the program know when the user has finished inputting data if less than 10 are required to be input?
Re: Help creating a do-while loop.
Have a counter that counts how many times a user enters a score, then you can do something like:
Code:
while (counter > 0)
{
//do whatever you want
counter--;
}
This could also be done with a for loop, which in my opinion would be more appropriate.
Code:
for (int i = counter; i < 0; i--)
{
//do whatever you want
}
Re: Help creating a do-while loop.
Quote:
Originally Posted by
zeroday
Have a counter that counts how many times a user enters a score, then you can do something like:
Code:
while (counter > 0)
{
//do whatever you want
counter--;
}
This could also be done with a for loop, which in my opinion would be more appropriate.
Code:
for (int i = counter; i < 0; i--)
{
//do whatever you want
}
oops, in my for loop it should be "i > 0" not what i have, sorry i dont know how to edit posts