lundi 27 mai 2019

Write a function ASTERISK in C++ Programming

I did a coding that accepts an integer from the user, and output the corresponding number of asterisks. For example:

Please enter a number: 10
* * * * * * * * * * 

I must use function concept to complete the coding only. I managed to get the correct number of asterisks but the '0' at the back just won't disappear.

#include<iostream>
using namespace std;

int NUMBER, i; 
int ASTERISK (int NUMBER);
int main ()

{
    cout << "Enter a number: " ;
    cin >> i ;
    cout << ASTERISK (i); 
    return 0;
}

int ASTERISK (int NUMBER){
    int ANSWER;
    for (NUMBER=1; NUMBER<=i; NUMBER=NUMBER+1){
        cout << "* " ;
    }
    return ANSWER;
}

Aucun commentaire:

Enregistrer un commentaire