Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

what is wrong with my code? I use C language

+6 votes
asked Dec 8, 2020 by Normal man Norman (180 points)
/* This program implements the pseudocode.

Written by:



#include <stdio.h>

int main (void)


// Local Declarations

float a;

float b;

float x;

float y;

float total;

// Statements

printf("Enter a number: ");

scanf ("%f", &x);

printf("Enter another number: ");

scanf ("%f", &y);

x = a * b;

y = a + b;

total = 3y + x * (y – a) * (x + b);

printf ("The total is %f\n", total);

return 0;

} // main

2 Answers

+3 votes
answered Dec 9, 2020 by Peter Minarik (66,990 points)

Problem #1

3y means nothing to the compiler. If you want 3 times y, you have to say

3 * y

Problem #2

A dash is not a minus sign.

Please note, that in the formula "total = 3y + x * (y – a) * (x + b);" you have a dash between y and a, not a minus sign

// – is a dash
// - is a minus sign
// correct formula:
total = 3 * y + x * (y - a) * (x + b);

Problem #3

The variables a and b are not read. You read x and y instead, but you instantly overwrite their value with calculation used by the uninitialized a and b.

Did you mean:

scanf("%f", &a);
scanf("%f", &b);


0 votes
answered Dec 10, 2020 by AJAY DHANGAR (140 points)
3*y and comment (//......//)

You wrote all the data in the comment.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.