Sign in to follow this  
Followers 0
tekwizz123

function program

2 posts in this topic

#include "stdafx.h"

#include "iostream"

#include "math.h"

using namespace std;

using namespace System;

int triangle(int i);

int main() {

int i;

cout<< "Insert a number to find the factoroid of.";

cin >> i;

cout<< "Function Returned \n"<< triangle(i)<< endl;

system (" pause ");

return 0;

}

int triangle (int i) {

int output = 0;

int n;

for (n=1; n<= i; n++)

output *= i;

return output;

}

this is my program. I want it to use factorial function on a number given by the user, but it keeps on giving 0 instead. What have I done wrong here?

0

Share this post


Link to post
Share on other sites

1.) Use code tags

2.) Post in the Programming/Code section

3.) "int output" is set to 0, so this:


output *= i;

won't do anything, since 0 * anything = 0.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0