1 Replies - 794 Views - Last Post: 05 January 2013 - 08:02 AM Rate Topic: -----

#1 liquid8souls  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-January 13

putting a multiplication table into a function

Posted 05 January 2013 - 07:50 AM

Hi
I am doing a project at the moment it compiles fine but i am getting an unexpected result being numbers on the end if anyone could give me an idea on why its coming up like this as its been a few hours and i cant seem to get it, also any feedback on coding or commenting that i can improve on thanks

#include<iostream>
#include<conio.h>
#include<iomanip>


using namespace std;
void Multitablefunc(int intMultDisplay);

int main ()
{//declaring variable section
	char charMenuchoice =' ';
	int intMultTable=0;
	int intMultDisplay=0;
	//welcome message for front screen
	cout<<"Do you want to create a multiplication table (M) or perform a Calculation (C)?"<<endl;
	cout<<"Enter (M) or (C) only "<<endl;
	//taking in char variable for menu selection
	cin>>charMenuchoice;

if (charMenuchoice=='M')//using M takes you into the multiplication table menu 
{
		system("CLS");
		cout<<"Please enter the number you want the multiplication table for "<<endl;
		cout<<"Note number must be between 1-20 "<<endl;
		cin>>intMultTable;

	while (intMultTable>20||intMultTable<0)
		cout<<"Sorry please enter a number between 1-20"<<endl;

	if(intMultTable<20 || intMultTable>0)
	{
		system("CLS");
		cout<<"Please enter how many lines of the table you want displayed."<<endl;
		cout<<"Note number should be between 1-15 only"<<endl;
		cin>>intMultDisplay;
		Multitablefunc( intMultDisplay);
		getch();
	}	

}
else if (charMenuchoice=='C')//when completed will have calculation functions 
	system("CLS");






return 0;
}
void Multitablefunc(int intMultDisplay)//multiplication table generator function
{
	
	 
	for( int i=1; i<=intMultDisplay; i++ )
	{
		cout<<setw(5)<<i;
		cout<< endl;
		for( int j = 1; j<=intMultDisplay ; j++ )
		{
			cout << setw(5)  << i*j ;
			
		}


	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: putting a multiplication table into a function

#2 liquid8souls  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-January 13

Re: putting a multiplication table into a function

Posted 05 January 2013 - 08:02 AM

sorry the minute i put this up i figured it out and i cant see how to delete this
so i will put my resolution

void Multitablefunc(int intMultDisplay)//multiplication table generator function
{
	
	 
	for( int i=1; i<=intMultDisplay; i++ )
	{
		cout<<setw(5)<<i;
		
		for( int j = 1; j<=intMultDisplay ; j++ )
		{
			cout << setw(5)  << i*j ;
			
		}
		cout<< endl;

	}
}


putting the endl outside the second forloops brackets
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1