How to alter the program so that when user types z or Z or 0, the program sets both a and b to zero?

Joined
Aug 12, 2022
Messages
6
Reaction score
0
Code:
#include <stdio.h>
#include <stdlib.h>

int main(void)

{
    char c;
    double a=0.0, b=0.0;
 
    do
    {
        system("cls");
        printf("==============\nCCurrent Values: \n");
        printf("a= %.2f, b= %.2f and a+b= %2.f", a, b,
        a+b);
        printf("\n\nYour Menu: ");
        printf("\na) Enter a new value for a");
        printf("\na) Enter a new value for b");
        printf("\nq) Quit");
        printf("\n Enter your choice:");
        scanf(" %c", &c);
      
        switch (c)
        {
            case 'A':
            case 'a':  printf("Enter value for a:");
                       scanf(" %lf", &a);
                       break;
          
            case 'B':
            case 'b':  printf("Enter value for b:");
                       scanf(" %lf", &b);
                       break;
          
            default:   break;
        }
    } while (c!='q' && c!='Q');
    return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top