MissAnnThropic MissAnnThropic - 1 year ago 81
C Question

Assignment to write a program that gives the user a choice between two options - C

I have an assignment due and I am drawing a blank on what exactly to do... I'm sure it is simple but I havent quite gotten the hang of things yet. The assignment is -

Write a program that gives the user 2 menu options: either call a function that will print a greeting and your name 4 times or call a function that will count down from 10 to 0 and then print "Blastoff!". Both functions should use for loops to print the appropriate output.

I have the prompt and the functions done so far... but I am unsure of how to display one or the other depending on the choice the user makes. Thank you for your help.

#include <stdio.h>

int main (void){
// declare counter variable
int i;

// prompt the user to make a choice
printf("What would you like to do?\n 1. Print my name\n 2. Count down from 10\n");

// display greeting and name 4 times
printf("Hi, my name is Bridget\n");

// display countdown
printf("%d\n", i);


Answer Source

you should use Switch case.

    switch(choice) {
     case 1: //first for loop
     case 2: //second for loop
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download