hi, my name is vic...i got one problem cannot fix....output for the number of times each of the tasks has been invoked...i run 3 times each of the tasks but the output always is this program has run 1 times.....

#include<stdio.h>
#include<stdlib.h>

void doTaskA(){
	printf("Start of Task A\n\n");
	int input_1, input_2, input_3;
	printf("Start of TASK A\n\n");
	printf("Please enter 3 integer.\n");
	scanf("%d\n%d\n%d",&input_1, &input_2, &input_3);
	if ((input_3>input_1) && (input_3>input_2))
		printf("/nThe biggest number is %d\n", input_3);
	else if ((input_2>input_1) && (input_2>input_3))
		printf("/nThe biggest number is %d\n", input_2);
	else 
		printf("/nThe biggest number is %d\n",input_1);
	
}



void doTaskB(){
int row, c, n, temp;
 
   printf("Start of Task B\n\n");
printf("Enter the number of rows in pyramid of stars you wish to see ");
   scanf("%d",&n);
 
   temp = n;
 
   for ( row = 1 ; row <= n ; row++ )
   {
      for ( c = 1 ; c < temp ; c++ )
         printf(" ");
 
      temp--;
 
      for ( c = 1 ; c <= 2*row - 1 ; c++ )
         printf("*");
 
      printf("\n");
   }
 
}



void doTaskC(){
 int n, c, k, space;
  printf("Start of Task c\n\n");
   
  scanf("%d", &n);
 
   space = 0;
 
   for ( k = n ; k >= 1 ; k-- )
   {
       for ( c = 1 ; c <= space ; c++ )
       printf(" ");
 
       space++;
 
       for ( c = 1 ; c <= k ; c++)
          printf("%d", c);
 
       printf("\n");
   }
 
   
}



void displayMenu(int &option) {
    
 
  
   printf("\nPlease choose one of the following :");
   printf("\n\n1. Task A\n");
   printf("2. Task B\n");
   printf("3. Task C\n");
   printf("4. Task D ( Exit This Program )\n");
   
   
   printf("\nPlease enter your selection :");
   scanf("%d",&option);
   
}

void howMany(){   
   
   static int count = 0;
   count++;
   
  
   printf("This program has run"  " %d "  "times\n\n\n",count);
   
   system("pause");

  }

 int main(){
	int option =0;
	bool exit = false;
    while(!exit) {
displayMenu(option);

		switch(option) {
			case 1:
				doTaskA();
				continue; 
			case 2:
				doTaskB();
				continue;
			case 3:
				doTaskC();
				continue;
			case 4:
				howMany();
				exit = true;
				break;
			default:
				printf("Incorrect selection. Try again.\n");
				continue;
}
}
	
	return 0;
}

You need to use an array of ints, one for each task. Or if you know there will be only 4 tasks then you can use 4 different int counters

int count1 = 0, count2 = 0, count3= 0;
int main(){
int option =0;
bool exit = false;
while(!exit) {
displayMenu(option);

switch(option) {
case 1:
doTaskA();
count1++;
continue; 
case 2:
doTaskB();
count2++;
continue;
case 3:
doTaskC();
count3++;
continue;
case 4:
howMany(count1,count2,count3);

exit = true;
break;
default:
printf("Incorrect selection. Try again.\n");
continue;
}
}

return 0;
}
[

You made Duplicate posts at the C and C++ forums and I received 3 private messages from you with the very same topic
You could have just made a single thread and waited patiently for a response from one our members

@AD
there's a [ at the end of your code

i try your code already, but got error......

i try your code already, but got error......

I'm not a mind reader so you need to tell us what the error was and post the code.

I'm not a mind reader so you need to tell us what the error was and post the code.

Error 5 error C2660: 'howMany' : function does not take 3 arguments

Error 5 error C2660: 'howMany' : function does not take 3 arguments

6 IntelliSense: too many arguments in function call

create the necessary arguments at your howMany function for it to work

create the necessary arguments at your howMany function for it to work

can u give me the example ???

void howMany(int count1, int count2, int count3 )

then print their values in the function

void howMany(int count1, int count2, int count3 )

then print their values in the function

when i run 3 times in my program, but output still zero......

Post your newest code.

Post your newest code.

#include<stdio.h>
#include<stdlib.h>

void doTaskA(){
	printf("Start of Task A\n\n");
	int input_1, input_2, input_3;
	printf("Start of TASK A\n\n");
	printf("Please enter 3 integer.\n");
	scanf("%d\n%d\n%d",&input_1, &input_2, &input_3);
	if ((input_3>input_1) && (input_3>input_2))
		printf("/nThe biggest number is %d\n", input_3);
	else if ((input_2>input_1) && (input_2>input_3))
		printf("/nThe biggest number is %d\n", input_2);
	else 
		printf("/nThe biggest number is %d\n",input_1);

 }



void doTaskB(){
	int row, c, n, temp;

	printf("Start of Task B\n\n");
	printf("Enter the number of rows in pyramid of stars you wish to see ");
	scanf("%d",&n);

	temp = n;

	for ( row = 1 ; row <= n ; row++ )  {	
		for ( c = 1 ; c < temp ; c++ )
			printf(" ");

		temp--;

		for ( c = 1 ; c <= 2*row - 1 ; c++ )
			printf("*");

		printf("\n");
	 }

 }



void doTaskC()  {
	int n, c, k, space;
	printf("Start of Task c\n\n");

	scanf("%d", &n);

	space = 0;

	for ( k = n ; k >= 1 ; k-- ) {
		for ( c = 1 ; c <= space ; c++ )
			printf(" ");

		space++;

		for ( c = 1 ; c <= k ; c++)
			printf("%d", c);

		printf("\n");
	}
 }






void displayMenu(int &option) {
	

	printf("\nPlease choose one of the following :");
	printf("\n\n1. Task A\n");
	printf("2. Task B\n");
	printf("3. Task C\n");
	printf("4. Task D ( Exit This Program )\n");


	printf("\nPlease enter your selection :");
	scanf("%d",&option);
 }
 
void howMany(int &count1, int &count2, int &count3)  { 
	int count = 0;
	count ++;

	printf("This program has run" " %d " "times\n\n\n",count);

	system("pause");
 }


int main(){
int count1 = 0, count2 = 0, count3= 0;
int option =0;
bool exit = false;
while(!exit) {
displayMenu(option);

switch(option) {
case 1:
doTaskA();
count1++;
continue; 
case 2:
doTaskB();
count2++;
continue;
case 3:
doTaskC();
count3++;
continue;
case 4:
howMany(count1,count2,count3);

exit = true;
break;
default:
printf("Incorrect selection. Try again.\n");
continue;
}
}

return 0;
}

You have to change HowMany() so that it displays the values of the 3 parameters. And those parameters don't have to be passed by reference. void howMany(int count1, int count2, int count3)

You have to change HowMany() so that it displays the values of the 3 parameters. And those parameters don't have to be passed by reference. void howMany(int count1, int count2, int count3)

i change already....still same the result.......

You have to change HowMany() so that it displays the values of the 3 parameters. And those parameters don't have to be passed by reference. void howMany(int count1, int count2, int count3)

can u modify again the code ?.....because tomorrow i need to pass up this code already....

If it is that urgent, this can be done quickly and easily using the dreaded global variable. Not to recommend extensive use of globals but just this once they could make for an easy solution:

int f1,f2;
void functionOne(/*functionOne arguments*/)
{
    f1++;//increment f1
    //code for function One
}
void functionTwo(/*functionTwo arguments*/)
{
    f2++;//increment f2
    //code for function Two
}
void showCounts()
{
    cout<<"functionOne: "<<f1<<" times.\nfunctionTwo: "<<f2<<" times.";
}
int main()
{
    showCounts();
    functionOne();
    showCounts();
    functionTwo();
    showCounts();
    return 0;
}

That is just an example of course, but you can use this principle in your code if you need to.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.