Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help creating a Do-While loop

Help creating a Do-While loop

Scheduled Pinned Locked Moved C / C++ / MFC
helplearning
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 10747711
    wrote on last edited by
    #1

    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;

    }

    G C 2 Replies Last reply
    0
    • U User 10747711

      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;

      }

      G Offline
      G Offline
      Garth J Lancaster
      wrote on last edited by
      #2

      think count adding a counter to count the number of scores, maybe

      int scorecount = 0;

      and at the end of a score 'collect', increment the counter

      scorecount += 1;

      then you need to add something like

      do
      {
      // something here
      }
      while scorecount //some test here ;

      around your logic - you textbooks/google should also be able to fill these gaps in for you Question : are you sure do-while is what you really need here - what are the pitfalls with it ? 'g'

      U 1 Reply Last reply
      0
      • G Garth J Lancaster

        think count adding a counter to count the number of scores, maybe

        int scorecount = 0;

        and at the end of a score 'collect', increment the counter

        scorecount += 1;

        then you need to add something like

        do
        {
        // something here
        }
        while scorecount //some test here ;

        around your logic - you textbooks/google should also be able to fill these gaps in for you Question : are you sure do-while is what you really need here - what are the pitfalls with it ? 'g'

        U Offline
        U Offline
        User 10747711
        wrote on last edited by
        #3

        Thank you very much Garth. Yes my text calls for a Do-While loop that runs up to 10 times and 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. Then I'll need to use either parallel arrays or a two-dimensional array in order to store the score, slope and rating for each entry, and variables for the handicap accumulator and number of scores entered.

        G 1 Reply Last reply
        0
        • U User 10747711

          Thank you very much Garth. Yes my text calls for a Do-While loop that runs up to 10 times and 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. Then I'll need to use either parallel arrays or a two-dimensional array in order to store the score, slope and rating for each entry, and variables for the handicap accumulator and number of scores entered.

          G Offline
          G Offline
          Garth J Lancaster
          wrote on last edited by
          #4

          fair enough - you can see then using a counter, that you might like to use that as the array index to store the values as well - just a thought :-) 'g'

          1 Reply Last reply
          0
          • U User 10747711

            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;

            }

            C Offline
            C Offline
            chinkeymouse
            wrote on last edited by
            #5

            Well,i'm glad to help you.It's my way to solve the problem.In my point,it's exactl solution.Thank you.

            Quote:

            //This program calculates a golfers handicap. #include #include using namespace std; int main() { int score, slope; double rating, handicap; string name; int time=1; cout << "This program calculates a golfer's handicap.\n"; cout << "Enter your name: "; cin >> name; cout << "Hello " << name << endl; //Have the user to input their name, score, slope, and handicap. do{ 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; time++; }while(time<=10); return 0; }

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups