Repeating Program Question

This is a discussion on Repeating Program Question within the C++ Programming forums, part of the General Programming Boards category; Hey, I am writing a do-while loop program that will ask a user for a number then print "I love ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    21

    Question Repeating Program Question

    Hey,
    I am writing a do-while loop program that will ask a user for a number then print "I love programming" that number of times. For example, if the user types in 3, then it would read "I love programming"
    "I love programming"
    "I love programming".

    So far this is all I have.
    I really am dumb-struck about what to do for the part where it repeats the words the certain amount of times.
    Help on what I should do to make it repeat enough would be greatly appreciated!

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main() 
    { 
    	int number;
    	char x;
    	x=1;
    
    cout << "Enter a number:" << endl;
    
    
    do
    {
    cin >> number;
    
    //what am i going to do here to make sure it prints "I love programming enough times???
    
    }
    while (x == 1);
    
    return 0;
    }
    Thanks, I sure hope someone can help me out!

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Let's say the user enters 3. Your condition on the WHILE need to test "number", not "x". You need to decrement "number" each time through the loop, and when you have depleted "number", you are done.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    21

    Yup, THanks, it works

    Allright, thanks a bunch, I got it to work, i was having a complete brain fart haha
    here it is:
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main() 
    { 
    	int x;
    	int i;
    	i=0;
    
    	cout << "Enter number:" << endl;
    	cin >> x;
    	do 
           {
              cout << "I love computer science" << endl;
              i++;
           } while (i <= x);
    
    
    return 0;
    }
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question regarding a this C program
    By cnb in forum C Programming
    Replies: 10
    Last Post: 10-11-2008, 04:43 AM
  2. newb question: probs with this program
    By ajguerrero in forum C Programming
    Replies: 5
    Last Post: 04-19-2006, 08:04 AM
  3. Random Question Assign Program
    By mikeprogram in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2005, 09:04 PM
  4. Question type program for beginners
    By Kirdra in forum C++ Programming
    Replies: 7
    Last Post: 09-15-2002, 05:10 AM
  5. Replies: 8
    Last Post: 03-26-2002, 06:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21