Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I'm new to programming and I don't understand how to finish my C program. How do I make the calculator loop when the user enters
I'm new to programming and I don't understand how to finish my C program. How do I make the calculator loop when the user enters a 1 and quit when the user enters a 0?
Also how do I do this function?
Bonus: Take a positive number (N) as an input (perform error check), print the numbers and calculate the sum of all numbers from 0 to N, also sum of all even numbers and sum of all odd numbers from 0 to N. (use for-loop)
Eg: Number is 4
0 1 2 3 4
Sum of all numbers is 10
Sum of even numbers = 6
Sum of odd numbers = 4
- int main(void) int option, units; while(1) displayMenu); printf('Choose a type of connection: ); scanf("%d", &option); if (errorCheck(option)) break; else printf("Invalid Choice! Please enter a valid choice '); while(1) printf("Enter the number of units (In kin):"); scanf("%d", &units); if (errorCheckUnits(units)) break; else printf(" Invalid input! Please enter a positive value '); //Calculations// float totalCharge - (float units + getRate(option, units)/100.0: printf("Total energy charge for the customer is %2f ", totalCharge); float totalBill - totalCharge + charge option): printf("Total Bill due from this connection is: %.21 ", totalBill); //Check for program loop// printf("Do you want to continue and calculate another bill? If yes enter 1, if not enter 0:"); scanf("%d", &option); while (option == 0){ breakStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started