Home > Software design >  How do I make this a loop?
How do I make this a loop?

Time:09-03

My Code is listed below.

I Used MS Visual C as my compiler.

#include <iostream>
using namespace std;

int main() {
    int num{};
    cout << "Enter a number: ";
    cin >> num;
    num = num * 2;
    cout << "Double the number you input is: " << num << endl;
    return 0;
}

CodePudding user response:

This will loop forever until you hit control-c:

#include <iostream>
using namespace std;

int main() {
    while( true ) {
        int num{};
        cout << "Enter a number: ";
        cin >> num;
        num = num * 2;
        cout << "Double the number you input is: " << num << endl;
    }
    return 0;
}
  • Related