#Functions, Scan, and Conditionals project

1 messages · Page 1 of 1 (latest)

shadow marsh
#

I have done a simple calculator project, but there seems to be many errors.
I have attatched my code so far and the instructions.

int main() {}
stuck sandalBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

shadow marsh
#

these are the instructions,

#

what is wrong with my code?

shadow marsh
#

I think my middle part is all correct

#

but it's my first and last part that's tripping me

#

nothing appears on the terminal when i try to run it

visual saffron
stuck sandalBOT
shadow marsh
#

@visual saffron this is the new thread

visual saffron
#

Yep, I am already looking at the code.

shadow marsh
#

ok thx

visual saffron
#

I think your understanding of a programming language may be a little "off".

shadow marsh
#

oh

visual saffron
#

A function may call another function.
Which in turn may call another function.

But that does not mean that all functions in a program must be "daisy-chained".

Your main() calls welcomeScreen().
welcomeScreen() then calls intermediateCalculator() and then prints "Thank You".

#

It doesn't quite work, and you could make it work like that.
But it's not quite right.

#

Function welcomeScreen() should just print a message to the screen.
When that's done, the function returns to main().
Then it should call intermediateCalculator().

shadow marsh
#

oh

#

but in the instructions i got

#

this is the last part

visual saffron
#

Whoaahh!

#

I am so sorry.

#

Ignore everything I said.
You are just following instructions.

shadow marsh
#

right yea

#

i provided the instruction pics on top

visual saffron
#

Yeah, sorry.
I cut a corner and didn't read those.

#

Bit me in the [redacted], as usual.

shadow marsh
#

it's alright it's alright

visual saffron
#

Your immediate issue is easily solved

void welcomeScreen (void) {
    printf("\nWelcome to the Intermediate Calculator~!\n");
    intermediateCalculator();
    printf("Thank you\n");
}
shadow marsh
#

that's the last part right?

visual saffron
#

No, the call to intermediateCalculator().

shadow marsh
#

so the start?

#

which part is that

visual saffron
#

Compare with yours.

void welcomeScreen (void) {
    printf("\nWelcome to the Intermediate Calculator~!\n");
    void intermediateCalculator (void);
    printf("Thank you\n");
}
#

I think you just copy and pasted the prototype and used it as a call to the function.

shadow marsh
#

right the void in the intermediate calcualtor is gone

#

ahh yea...

#

umm ok

#

i have encounteredd a problem

#

it all works fine

#

but

#

The outcome for the expression came out to be {finalOutcome}

#

it says this

#

instead of actually giving the final outcome

visual saffron
#

What do you enter?
(ik, probably in one of those screenshots)

shadow marsh
#

Welcome to the Intermediate Calculator~!
Welcome to the Intermediate Calculator~!
You will be providing four numbers and three operators!
The numbers must be integers and the operators must be add, subtract, multiply, divide, or remainder!
Please enter the expression below:
1 * 3 * 5 + 4
The outcome for the expression came out to be {finalOutcome}
Thank you

#

this is what i get

#

else {
if (operator_two == '+'){
finalOutcome = firstSecondOutcome + thirdFourthOutcome;
}
else if (operator_two == '-'){
finalOutcome = firstSecondOutcome - thirdFourthOutcome;
}
else if (operator_two == '*'){
finalOutcome = firstSecondOutcome * thirdFourthOutcome;
}
else if (operator_two == '/'){
finalOutcome = firstSecondOutcome / thirdFourthOutcome;
}
else {
finalOutcome = firstSecondOutcome % thirdFourthOutcome;
}
}
printf("The outcome for the expression came out to be {finalOutcome}\n");
}

visual saffron
#
printf("The outcome for the expression came out to be %d\n", finalOutcome);
stuck sandalBOT
#

@shadow marsh Has your question been resolved? If so, type !solved :)

visual saffron
#

@shadow marsh
From the assignment:

If operator_one is *, /, or %

You are using && which is AND.
You want || for OR.

And also:

If firstOperatorFlag is 2 and secondOperatorFlag is 2

You are using , which is not AND.
You want && here.

(neither emphasis mine)

visual saffron
#
Welcome to the Intermediate Calculator~!
Welcome to the Intermediate Calculator~!
You will be providing four numbers and three operators!
The numbers must be integers and the operators must be add, subtract, multiply, divide, or remainder!
Please enter the expression below: 
1 * 3 * 5 + 4
firstSecondOutcome = 1 * 3 = 3
firstSecondThirdOutcome = 3 * 5 = 15
finalOutcome[1] = 15 + 4 = 19
The outcome for the expression came out to be 19
Thank you

And

Welcome to the Intermediate Calculator~!
Welcome to the Intermediate Calculator~!
You will be providing four numbers and three operators!
The numbers must be integers and the operators must be add, subtract, multiply, divide, or remainder!
Please enter the expression below: 
4 + 5 * 6 / 10
secondThirdOutcome = 5 * 6 = 30
secondThirdFourthOutcome = 30 / 10 = 3
finalOutcome[2] = 4 + 3 = 7
The outcome for the expression came out to be 7
Thank you
#

You were very close.
Just those two bugs I mentioned.

shadow marsh
#

oh, ok

#

ok wait

#

so the code i have right now is

#

this is the code I have

#

but it doesn't work

#

it says there is an error

#

@visual saffron

cerulean raptor
#

What’s the error message

shadow marsh
#

Calculator.c:179:48: error: expression is not assignable
if (firstOperatorFlag = 2&& secondOperatorFlag = 2){
~~~~~~~~~~~~~~~~~~~~~~ ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
2 errors generated.

dawn brook
shadow marsh
#

ok

#

well

#

there seems to be a problem with my middle code

#

Welcome to the Intermediate Calculator~!
You will be providing four numbers and three operators!
The numbers must be integers and the operators must be add, subtract, multiply, divide, or remainder!
Please enter the expression below:
3 * 4 + 5 * 5
The outcome for the expression came out to be -1
Thank you

#

i'm pretty sure 3 4 + 55

#

is not -1

#

what is the problem here?

stuck sandalBOT
#

@shadow marsh Has your question been resolved? If so, type !solved :)

shadow marsh
#

no

#

now this is the function I have

#

but something is wrong

#

the finaloutcome does not come out right

#

there's seomthign wrong with multiplication I thin

#

Yea i tested everything

#

and the only thing that doesn't work is related to multiplication

#

!solved