online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <unistd.h> #include <string.h> void help(void); int calculator(int argc, char **argv); int error_handling(int stars, int days); void premium_mode(int stars, int days); int calculator_mode(int stars, int days); int main (int argc, char **argv) { char const *help_str = "-h"; if (argc == 2 && strcmp (help_str, argv[1]) == 0) { help (); return (0); } else if (argc == 1) { write (2, "You must add arguments\n", 24); exit (84); } else { calculator (argc, argv); } } void help(void) { write (1, "USAGE Click on run -> Add the arguments in the text box below\n\n", 73); write (1, "Arguments = [Number of Stars] [Number of days left before the challenge ends] [-p]\n\n", 84); write (1, "The -p option is the premium simulation, to enable this mode, just add `-p` at the end of the arguments\n", 105); } int calculator(int argc, char **argv) { if ((argc != 3) && (argc != 4)) { printf ("Invalid arguments\n"); exit (84); } int stars = atoi (argv[1]); int days = atoi (argv[2]); char const *premium = "-p"; error_handling (stars, days); if (argc == 4 && strcmp (premium, argv[3]) == 0) { premium_mode (stars, days); return (0); } calculator_mode (stars, days); } int error_handling(int stars, int days) { if (stars >= 3000) { printf ("You have finished the challenge\n"); exit (84); } if (stars < 0) { printf ("Invalid Number of stars\n"); exit (84); } if (days < 0 || days > 15) { printf ("Invalid number of days\n"); exit (84); } } void premium_mode(int stars, int days) { float percentage = stars; float step1 = (percentage / 3000) * 100; stars = 3000 - stars; double stars_to_do = stars; double days_to_do = days; double result = stars_to_do / days_to_do; printf ("Percentage achieved: %.2f%\n", step1); printf ("Number of days left: %d\n", days); printf ("Number of stars left: %d\n", stars); printf ("Stars to do per day: %.0f\n", result); printf ("With premium mode: From 2 to 6 stars available per battle\n"); } int calculator_mode(int stars, int days) { float percentage = stars; float step1 = (percentage / 3000) * 100; stars = 3000 - stars; double stars_to_do = stars; double days_to_do = days; double result = stars_to_do / days_to_do; printf ("Percentage achieved: %.2f%\n", step1); printf ("Number of days left: %d\n", days); printf ("Number of stars left: %d\n", stars); printf ("Stars to do per day: %.0f\n", result); printf ("Without premium mode: From 1 to 3 stars available per battle\n"); }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue