Question

In: Computer Science

I HAVE THIS PROBLEM: Create a new Project and name it - InClassParticipation3 Get up to...

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!!

Solutions

Expert Solution

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


Related Solutions

Problem 1 Create a new project called Lab7 Create a class in that project called ListORama...
Problem 1 Create a new project called Lab7 Create a class in that project called ListORama Write a static method in that class called makeLists that takes no parameters and returns no value In makeLists, create an ArrayList object called avengers that can hold String objects. Problem 2 Add the following names to the avengers list, one at a time: Chris, Robert, Scarlett, Clark, Jeremy, Gwyneth, Mark Print the avengers object. You will notice that the contents are displayed in...
Stack Create a New Project and give your project a name, say. Download the given source...
Stack Create a New Project and give your project a name, say. Download the given source files StackArr.h and StackArr.cpp from Moodle and save them to your Lab6a folder. Also import them to your project. Add a source file to your project, called StackMain.cpp and implement your program according to the following: Prompt the user to input a program filename. Open the file and check if every right brace (i.e. }), bracket (i.e. ]), and parenthesis (i.e. )) in the...
HW_6a - Read a text file Create a new C++ project and name it as:   Numbers...
HW_6a - Read a text file Create a new C++ project and name it as:   Numbers Create a text file and     save it as:   data.txt Create and save the file      in a C++ project      in the Resource folder. Enter the following numbers:        3                                                              4                                                              5       Note:   After you enter the 5, don’t press the enter key. Save and close the file. Add another file and name it:   Source.cpp Write one statement that declares a file...
Part 1: Stack Create a New Project and give your project a name, say Lab6a. Download...
Part 1: Stack Create a New Project and give your project a name, say Lab6a. Download the given source files StackArr.h and StackArr.cpp from Moodle and save them to your Lab6a folder. Also import them to your project. Add a source file to your project, called StackMain.cpp and implement your program according to the following: Prompt the user to input a program filename. Open the file and check if every right brace (i.e. }), bracket (i.e. ]), and parenthesis (i.e....
Process Cost Excel Project Create a new Excel spreadsheet and name it “Last name_PC”. You project...
Process Cost Excel Project Create a new Excel spreadsheet and name it “Last name_PC”. You project is to create a model for a production cost report using the weighted average method for the month of May.   Following good Excel design techniques, you should have an input area in which you put the department information for the month, and an output area that calculates the production cost report. As always, you should have only formulas or references in your output area....
Process Cost Excel Project Create a new Excel spreadsheet and name it “Last name_PC”. You project...
Process Cost Excel Project Create a new Excel spreadsheet and name it “Last name_PC”. You project is to create a model for a production cost report using the weighted average method for the month of May.   Following good Excel design techniques, you should have an input area in which you put the department information for the month, and an output area that calculates the production cost report. As always, you should have only formulas or references in your output area....
Process Cost Excel Project Create a new Excel spreadsheet and name it “Last name_PC”. You project...
Process Cost Excel Project Create a new Excel spreadsheet and name it “Last name_PC”. You project is to create a model for a production cost report using the weighted average method for the month of May.   Following good Excel design techniques, you should have an input area in which you put the department information for the month, and an output area that calculates the production cost report. As always, you should have only formulas or references in your output area....
You have to get a new driver's license and you show up at the office at...
You have to get a new driver's license and you show up at the office at the same time as 4 other people. The office says that they will see everyone in alphabetical order and it takes 20 minutes for them to process each new license. All of the agents are available now, and they can each see one customer at a time. How long will it take for you to walk out of the office with your new license?...
Create a new project in BlueJ. Create two new classes in the project, with the following...
Create a new project in BlueJ. Create two new classes in the project, with the following specifications: Class name: Part Fields: id (int) description (String) price (double) onSale (boolean) 1 Constructor: takes parameters partId, partDescrip, and partPrice to initialize fields id, description, and price; sets onSale field to false. Methods: Write get-methods (getters) for all four fields. The getters should be named getId, getDescription, getPrice, and isOnSale.
Create a C# console application (do not create a .NET CORE project) and name the project....
Create a C# console application (do not create a .NET CORE project) and name the project. Generate two random integers, each between 1 and 50, that you will be adding together to test the user's ability to perform the addition operator. Display the numbers in the console, such as:             7 + 22 = ? Once the user provides their answer, check to see if it is correct and if not, tell them sorry, please try again. If their answer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT