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;
}

Recommended Answers

All 2 Replies

[boilerplate_help_info]

Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information.
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a cheater. 
    If you use that code [i]you[/i] are a cheater.
[*]Do [b]not[/b] bore us with how new you are. We can tell by your code.
- Do not apologize. We were all new, and unless you are completely 
  brain dead you will get better.
- Do not ask us to "take it easy on you."
- Do not say "I don't know what's going on." That's obvious since
  you posted for help. Use that time wisely by [b]explaining[/b] as best 
  you can so we can help.
[*]Do not apologize for posting 'late'. We don't have any expectations on when you should be posting - 10 minutes or 10 days. We aren't timing your responses.
[*][b]Do not post your requirements and nothing else. [/b]We view that as a lazy do-nothing student that wants us to do their work for them. That's cheating and we [i]will[/i] be hard on you.
[*]Do not attach files except when absolutely necessary. Most of us are not going to download files.  Add the information to your post.
[*][b]Do not tell us how urgent it is.[/b] Seriously, for us there is no urgency at all. Many that can help will ignore any URGENT or ASAP requests.
[*]Create a [b][i]good[/i][/b] title for your post. The title [b]C++[/b] in the C++ forum is bloody redundant and worthless!  [b]What's wrong?[/b] equally so. What are you having trouble with? [i]There[/i] is your title. [i](note: [b]my program[/b] is not the answer.)[/i]
[/list]
Think more about your next post so we don't have to play 20 questions to get the info we need to help you.

[/boilerplate_help_info]

commented: It's not hard to get the code into proper formatting. -1

OK, look at your main function:

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;
}

I'm not sure why you're using continue instead of break. The break would only exit out of the switch block and not the while loop.
So... after each of the tasks, you should be incrementing a counter. However, that counter is located here:

void howMany(){

	static int count = 0;
	count++;

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

	system("pause");

}

HowMany is only getting called at the end of the program. Therein lies your problem.
My recommendation: yank the count variable declaration from howMany and make it global. Then, after each task is run, put count++; after each of their respective blocks (except number 4 and the default) in the switch.

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.