How do I fix error "use of undeclared identifier n" in C? -
i'm sure there tons of syntax/other errors, i'm trying figure out 2 it's picking on. i'm new don't know how fix undeclared identifiers. note #include <cs50.h>
cs50's library.
#include <cs50.h> #include <stdio.h> int main (void) { int add, fee, disc; printf("for rate tax , security deposit, type y. 10 percent off, type n:"); string name = getstring(); if (name == y) { printf("pretax amount: "); scanf("%d", &fee); printf("okay. add 10 percent tax %d.\n ", fee); add = (1.1 * fee); printf("plus tax amount = %d\n", add); printf("security deposit = 1000 dollars\n"); printf("total = (%d + 1000)", add); } else if (name == n) { printf("pretax amount: "); scanf("%d%d", &fee, &disc); printf("okay. minus 10 percent discount %d , add tax.\n ", fee); add = (0.9 * fee); disc = (add * 1.1); printf("minus discount amount plus tax = %d\n", disc); printf("security deposit = 1000 dollars\n"); printf("total = (%d + 1000)", disc); } return 0; }
errors:
contractualhelper.c:10:17: error: use of undeclared identifier 'y' if (name == y) ^ contractualhelper.c:22:22: error: use of undeclared identifier 'n' else if (name == n) ^ 2 errors generated.
y
, n
undeclared because not have definitions.
int y;
declaration, rid of error.
however, code
if (name == y)
is comparing variable name
variable y
, , think want see if name
contains string y
.
how comparison issue.
Comments
Post a Comment