In: Computer Science
I HAVE THIS PROBLEM:
Create a new Project and name it - InClassParticipation3
Get up to 5 inputs from the user. The user must enter at least 1
number.
After the first input, ask them if they would like to input another
number, if they say 'yes' get the provided input and multiply it to
the other inputs provided by the user.
If the user says 'no', do not prompt them to input anymore numbers
and then figure out if the number is divisible by 3, 5, both 3 AND
5, or none of the provided options.
If the number is divisible by 3, output the number and then
'YAY'.
If the number is divisible by 5, output the number and then
'ME'.
If the number is divisible by both 3 and 5, output the number and
then 'YAYME!!'.
If it is not divisible by either 3 or 5, simply just output the
number.
**THE CODE I HAVE WRITTEN SO FAR IS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace InClassParticipation3_1
{
class Program
{
static void Main(string[] args)
{
double val1, val2, val3, val4, val5;
string answer;
int total;
Console.WriteLine("Please enter a number.");
val1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Would you like to enter another value? Answer
yes or no.");
answer = Console.ReadLine();
if (answer == "yes")
{
Console.WriteLine("Enter the second value.");
val2 = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Would you like to enter another value? Answer
yes or no.");
answer = Console.ReadLine();
if (answer == "yes")
{
Console.WriteLine("Enter the third value: ");
val3 = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Would you like to enter another value? Answer
yes or no.");
answer = Console.ReadLine();
if (answer == "yes")
{
Console.WriteLine("Enter the fourth value: ");
val4 = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Would you like to enter another value? This is
the last one!! Answer yes or no.");
answer = Console.ReadLine();
Console.WriteLine("Enter the fifth value: ");
val5 = Convert.ToInt32(Console.ReadLine());
if (total % 3 == 0 && total %
5 == 0) **THE ERROR IS HERE ON THE "total" IN THE FIRST
"If" STATEMENT.???
{
Console.WriteLine("YAYME!!");
}
else if (total % 3 == 0)
{
Console.WriteLine("YAY");
}
else if (total % 3 == 0)
{
Console.WriteLine("ME");
}
else
{
Console.WriteLine(total);
}
// Console.WriteLine("The total of the three values you entered is:
" + sum);
//Console.WriteLine("The total of the three values you entered is:
" + mulpSum);
//Console.ReadKey();
}
}
}
**PLEASE HELP ME FIGURE OUT WHAT I AM DOING WRONG!!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace InClassParticipation3_1
{
class Program
{
static void Main(string[] args)
{
double val1, val2, val3, val4, val5;
string answer;
// we have initialize before using it
int total=0;
Console.WriteLine("Please enter a number.");
val1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Would you like to enter another value? Answer yes or no.");
answer = Console.ReadLine();
if (answer == "yes")
{
Console.WriteLine("Enter the second value.");
val2 = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Would you like to enter another value? Answer yes or no.");
answer = Console.ReadLine();
if (answer == "yes")
{
Console.WriteLine("Enter the third value: ");
val3 = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Would you like to enter another value? Answer yes or no.");
answer = Console.ReadLine();
if (answer == "yes")
{
Console.WriteLine("Enter the fourth value: ");
val4 = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Would you like to enter another value? This is the last one!! Answer yes or no.");
answer = Console.ReadLine();
Console.WriteLine("Enter the fifth value: ");
val5 = Convert.ToInt32(Console.ReadLine());
if (total % 3 == 0 && total % 5 == 0)
{
Console.WriteLine("YAYME!!");
}
else if (total % 3 == 0)
{
Console.WriteLine("YAY");
}
else if (total % 3 == 0)
{
Console.WriteLine("ME");
}
else
{
Console.WriteLine(total);
}
// Console.WriteLine("The total of the three values you entered is: " + sum);
//Console.WriteLine("The total of the three values you entered is: " + mulpSum);
//Console.ReadKey();
}
}
}
Issue: here your using total variable with out initializing any value so it is throwing the error Now i have initialized the value