Need Help With These 2 HW Questions.
// Question 2: Design a C# program that prompts the result (ans) of the following expression.
double v1 = 45.7;
double v2 = 10.5;
int v3 = 5;
// v1 += v1++;
// --v2;
double ans1;
ans1 = (int)v1 + v2 / (double)v3;
Console.WriteLine(ans1);
// Question 3.1: Design a C# program that prompts the result (ans) of the following expression.
double v1 = 45.7;
double v2 = 10.5;
int v3 = 5;
// v1 += v1++;
int ans2;
ans2 = (int)v1 + --v2 / (double)v3++;
Console.WriteLine(ans2);
15 Replies
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/to make it easier to read
What are you having trouble with?
First, I'm confused about my HW premise, like not sure if they want to find the result using C# and in general how to create a code for this? Don't know what to do with v1 += v1++;
--v2;
I won't interpret your hw assignment for you, and I agree with the question phrasing being vague on what they want. That's between you and your teacher.
If you need help getting started with C# here's a basic instruction on how to create and run code https://learn.microsoft.com/en-us/training/modules/install-configure-visual-studio-code/7-exercise-create-build-run-app
Exercise - Create, build, and run your application - Training
Exercise - Create, build, and run your application
there's also later steps on how to create variables etc, which could help you
if you have trouble with any of those steps I'm happy to help you create an application or write code 🙂
Do you have any advise for me on how to do the 2 Questions, I think they want me to find the result using C#?
Yup. The content given is not valid C#, so I think they want you to create an application that displays the answer to the console. That is my interpretation of the assignment
I would verify with your teacher if that's correct
It's due tonight soon and I haven't gotten a reply back from my Profressor.
then I'd say run with that. Make a C# application that outputs the answer
This has to be one of the weirdest formats of a hw question I have seen
double v1 = 45.7;
double v2 = 10.5;
int v3 = 5;
// v1 += v1++;
// --v2;
double ans1;
ans1 = (int)v1 + v2 / (double)v3;
Console.WriteLine(ans1);
// Question 3.1: Design a C# program that prompts the result (ans) of the following expression.
double v1 = 45.7;
double v2 = 10.5;
int v3 = 5;
// v1 += v1++;
int ans2;
ans2 = (int)v1 + --v2 / (double)v3++;
Console.WriteLine(ans2);
is this correct? I'm not sure what to do with ans2 = (int)v1 + --v2 / (double)v3++;
if you want to see for yourself
not sure what you mean. It just looks like you have the type of
ans2
wrong. It would be a double instead of int
if you want an int it would be
Thanks.