This code in C works properly when I use code::blocks or any online compilers, however if I try to use this in VSCODE it returns
“expected type-specifier before ‘;’ token on LN 5, Col 18”
“expected type-specifier before ‘)’ token on LN 13, Col 26”
“expected type-specifier before ‘)’ token on LN 20, COL 21”
this is the code that i was referring to
+
#include <stdio.h>
#include <ctype.h>
int main() {
char operator;
double num1;
double num2;
double result;
char choice;
do {
printf("Enter the operator you want to use: ");
scanf("%c", &operator);
printf("Number 1: ");
scanf("%lf", &num1);
printf("Number 2: ");
scanf("%lf", &num2);
switch (operator)
{
case '+':
result = num1 + num2;
printf("The Sum is: %.1lfn", result);
break;
case '-':
result = num1 - num2;
printf("The Difference is: %.1lfn", result);
break;
case '/':
result = num1 / num2;
printf("The Quotient is: %.3lfn", result);
break;
case '*':
result = num1 * num2;
printf("The Product is: %.1lfn", result);
break;
default:
printf("That is not a valid operator! n");
break;
}
printf("Do you want to compute again?: Y/N ");
scanf(" %c", &choice);
choice = toupper(choice);
while ((getchar()) != 'n');
}while (choice == 'Y');
return 0;
}
I tried changing the char operators; but to no avail. this problem shows up on VSC only
shenzainn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
You are compiling it as a C++ program and it’s not a valid C++ program since operator
(as in char operator;
) is a keyword in C++. You can’t declare variable named operator
in C++. You need to save your program as a C program and recompile.