Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
exam ata
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
// Online C compiler to run C program online #include <stdio.h> float getSum(float a, float b); int main(void) { int opt = 0; while ( opt >= 0 ) { printf("A VOID USER-DEFINED FUNCTION FOR:\n"); printf("OPTION 1: Addition\n"); printf("OPTION 2: Subtraction\n"); printf("OPTION 3: Division\n"); printf("OPTION 4: Multiplication\n"); printf("OPTION 5: Power\n"); printf("OPTION 0: End Program\n\n\n"); printf("Input the case number for your operation: "); scanf("%d", &opt); // OPTION 6: End program // printf("Enter option again. Press 0 to return, Press -1 to end\n"); if ( opt == 0 ) { break; } else if ( opt == 1 ) { int addOpt = opt; while ( addOpt > 0 ) { float a, b, sum; printf("Enter a first value: "); scanf("%f", &a); printf("\nEnter a second value: "); scanf("%f", &b); sum = getSum(a, b); printf("\nSum is: %f\n", sum); printf("Would you like to return to the main menu?\n"); printf("Input 0 to return, Input -1 to end: "); scanf("%d", &addOpt); printf("\n"); if ( addOpt == 0 ) { printf("Loading Main...\n"); break; } else if ( addOpt == -1 ) { addOpt = opt; printf("\n"); } } } } return 0; } float getSum(float a, float b) { float result; result = a + b; return result; }
[
+
]
Show input
edit mode
|
history
|
discussion