I don't even know where to start

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • snhamilton
    New Member
    • Sep 2006
    • 5

    I don't even know where to start

    Intro level problem; should be easy



    Given an int variable k that has already been declared, use a while loop to print a single line consisting of 97 asterisks. Use no variables other than k .
  • pukur123
    New Member
    • Sep 2006
    • 61

    #2
    Here your aim is to print 97 asterisks in one line. So you have to start a counter and let k be the counter and initialise it by 0.

    Now start a while loop with the condition that is k < 97(see your counter starts with 0).

    Inside the loop print one asterisk and increment the counter. So the loop will keep on printing the asterisks for k=0,1,2,....... ,96 and when the value of k will become 97 the loop terminates and you will get 97 asterisks in one line.

    So give a try.

    Comment

    • Nor farhana yaakub
      New Member
      • Sep 2006
      • 12

      #3
      hi pukur123,i have try and it is like this........it' s right....and i get the "*" print 97 times in a straight lines....
      like this..
      *
      *
      *
      *
      *
      *
      *
      .
      .
      .
      .
      ..
      thanks ya


      #include<iostre am>
      using namespace std;
      int main()
      {
      int k=0;
      while(k<97)
      {
      cout<<"*"<<endl ;
      k++;
      }
      }

      Comment

      • pukur123
        New Member
        • Sep 2006
        • 61

        #4
        Try this one....

        #include<iostre am>
        using namespace std;
        int main()
        {
        int k=0;
        while(k<97)
        {
        cout<<"*\n"<<en dl;
        k++;
        }
        }

        Comment

        • D_C
          Contributor
          • Jun 2006
          • 293

          #5
          If you want a row of 97 asterisks, instead of a column of 97 asterisks, The output statement should be cout << "*"; instead of cout << "*" << endl;

          Comment

          • Nor farhana yaakub
            New Member
            • Sep 2006
            • 12

            #6
            thanks,i am much clearer now..better understanding.. .(*_*)

            Comment

            • radhakrishna
              New Member
              • Sep 2006
              • 3

              #7
              Originally posted by snhamilton
              Intro level problem; should be easy



              Given an int variable k that has already been declared, use a while loop to print a single line consisting of 97 asterisks. Use no variables other than k .
              hi,
              i am writing a sample code for that in my standard as follows


              int k;
              k = 1;
              while( k <= 97)
              {
              printf("*");
              k++;
              }

              Comment

              • dush
                New Member
                • Sep 2006
                • 27

                #8
                int k=97;
                while(k--) cout << '*';

                Comment

                Working...