Rewrite Python and C++ code in C# Part 1: Python code, rewrite this code in C#,
ID: 3873090 • Letter: R
Question
Rewrite Python and C++ code in C# Part 1: Python code, rewrite this code in C#, run the program and submit-include comments 1, number= 4 2. guesscount-0 3. guess-int(input Guess a number between 1 and 10:") 4. while guess-number: 5. guesscount-guesscount+1 6. if guess number: 9. print(Your guess is too high") 10. else 11. print("You got it!!") 12. guess-int(input( Guess again: ") 13. print You figured it out in ".guesscount," guesses") Part 2: C++ code: rewrite the following code in C# Run the program and submit. include comments 1. #include 2. using namespace std 4. int main0 6. int count=1, total=0 7. while(countExplanation / Answer
Part 1:
using System.IO;
using System;
class Program
{
static int Main()
{
int number=4,guesscount=0,guess;
Console.Write("Guess a number between 1 and 10:");
guess=Console.Read();
while(guess!=number)
{
guesscount=guesscount+1;
if(guess<number)
Console.WriteLine("Your guess is too low");
else
if(guess>number)
Console.WriteLine("Your guess is too high");
else
Console.WriteLine("You got it");
Console.Write("Guess again:");
guess=Console.Read();
}
Console.WriteLine("You figured it out in ");
Console.Write(guesscount);
Console.Write("guesses");
return 0;
}
}
Part 2:
using System.IO;
using System;
class Program
{
static int Main()
{
int count=1,total=0;
while(count<=100)
{
total+=count;
count++;
}
Console.WriteLine("The sum of the numbers 1-100 is: ");
Console.WriteLine(total);
return 0;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.