We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,682 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Need Help (Newb Question)

Okay, I keep getting an error stating that I have few arguments in my void function. I changed it so many time with different combination and yet I still get this error. I just simply want the program to print each digit in a vertical line.

#include <iostream>
#include <cmath>
using namespace std;



void vertical(int &a, int digit[]);


int main () {
        int a;
        cout << "Please enter a 4 digit number" << endl;
        cin >>a;
        while( a>999 && a<10000) {

        vertical(a);
        cout << "Please enter a 4 digit number" << endl;
        cin >> a;
        }
        return 0;
}


void vertical(int &a, int digit[]) {
        for (int i = 0; i < 4; i++){
        digit[i] = a % 10;
        a = a/10;
        }
        cout << digit[0] << endl;
        cout << digit[1] << endl;
        cout << digit[2] << endl;
        cout << digit[3] << endl;
}
2
Contributors
1
Reply
1 Hour
Discussion Span
7 Months Ago
Last Updated
2
Views
JustHere155
Newbie Poster
1 post since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Look at the function prototype on line 7, it has two arguments. Now look at line 16, it is passing only one argument. The compiler is complaining because line 16 is not passing enough arguments. In main() declare an array of ints and add that array as the second argument on line 16.

The function that starts on line 24 is going to have problems. The first parameter, variable named "a" is a pointer, but you are using it inside the function as if it is not a pointer. It can't be both ways. I'd suggest you remove the pointer & opeator on both lines 7 and 24 because the function does not need a pointer for that variable.

Suggestion: you don't need both lines 12 & 13, and 17&18. Rearrange main() so that lines 17 & 18 appear only once in your program. You should find ways to eliminate repeated code in your programs.

Ancient Dragon
Achieved Level 70
Team Colleague
32,109 posts since Aug 2005
Reputation Points: 5,836
Solved Threads: 2,575
Skill Endorsements: 68

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0771 seconds using 2.65MB