vendredi 19 septembre 2014

Hello Can someone let me know why this code won't compile


Vote count:

0




Hey guys this code will not compile, it is for this project:


University of Massachusetts Dartmouth


Department of Electrical and Computer Engineering


ECE 264 ______Name: guess.cs Project1 ___Due: 09/16/2014 Overview


For this project, you will be entering the program using a text editor (either notepad or MSWord and save in text mode). The file extension should be .cs. You will be running the C# compiler from the command line. Open a command window (click Start, type cmd in the search box and press enter). Once the command window is displayed, type one of the following to setup the correct environment (you need to type the quotes) 64 bit OS: "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\vsvars32" 32 bit OS: "C:\Program Files\Microsoft Visual Studio 12.0\Common7\Tools\vsvars32" You may then type: csc guess.cs to compile your program, and guess to run it. Problem Statement: For this project you will be creating a guessing game based on simple data types used in C#. Your program’s should output a number and based on the value and formatting, the user must enter a data type that matches the number’s (or character’s) formatting. The program will then prompt if a smaller data type could have been used to hold that value. Your program should also offer a reversed option of the game. If you type in a value, then it should output the correct data type. This program should utilize byte, sbyte, int, uint, short, ushort, long, ulong, char, float, double, decimal and string. Hint: Looping statements and branches will really help you to control how your program processes data.



/*referenced http://ift.tt/1mgHMZB */
using System;
using System.Collections.Generic;
using System.Text;

namespace Guess
{
class Program
{
static void Main(string[] args)
{
while (true)
{
string Value = 0;
string UserValue = 0;
int Switch = GenerateNumber(1,13);
Console.WriteLine("I want to play a guessing game... do you want to guess first? (1=yes or 0=no) \r\n");
int intTemp = Convert.ToInt32(Console.Readline());
if(intTemp == 0)
{
Console.WriteLine("\r\n OK... I will guess first... please type in a value: \r\n");
UserValue = Console.Readline();
/*is it a string or a char?*/
if(char.isLetter(UserValue)
{
if(UserValue.Length == 1)
{
Switch = 9;
}
else
{
Switch = 13;
}
}
/*rest of the logic for 11 different data types */
if(UserValue => byte.MinValue && UserValue =< byte.MaxValue)
{
Switch = 1;
}
else if(UserValue => sbyte.MinValue && UserValue =< sbyte.MaxValue)
{
Switch = 2;
}
else if(UserValue => short.MinValue && UserValue =< short.MaxValue)
{
Switch = 5;
}
else if(UserValue => ushort.MinValue && UserValue =< ushort.MaxValue)
{
Switch = 6;
}
else if(UserValue => int.MinValue && UserValue =< int.MaxValue)
{
Switch = 3;
}
else if(UserValue => uint.MinValue && UserValue =< uint.MaxValue)
{
Switch = 4;
}
else if(UserValue => long.MinValue && UserValue =< long.MaxValue)
{
Switch = 7;
}
else if(UserValue => ulong.MinValue && UserValue =< ulong.MaxValue)
{
Switch = 8;
}
else if(UserValue => float.MinValue && UserValue =< float.MaxValue)
{
Switch = 10;
}
else if(UserValue => double.MinValue && UserValue =< double.MaxValue)
{
Switch = 11;
}
else if(UserValue => decimal.MinValue && UserValue =< decimal.MaxValue)
{
Switch = 12;
}
}
/*datatype case */
switch(Switch);
{
case 1:
/*byte*/
value = GenerateNumber(byte.MaxValue,byte.MinValue);
Console.WriteLine(value);
if(intTemp == 1)
{
Console.WriteLine("Please enter a value that matches the format:");
UserValue = Console.Readline();
if(UserValue => byte.MinValue && UserValue =< byte.MaxValue)
{
Console.WriteLine("CORRECT!");
}
else
{
Console.WriteLine("WRONG!");
}
}
break;
case 2:
/*sbyte*/
value = GenerateNumber(sbyte.MaxValue,sbyte.MinValue);
Console.WriteLine(value);
if(intTemp == 1)
{
Console.WriteLine("Please enter a value that matches the format:");
UserValue = Console.Readline();
if(UserValue => sbyte.MinValue && UserValue =< sbyte.MaxValue)
{
Console.WriteLine("CORRECT!");
}
else
{
Console.WriteLine("WRONG!");
}
}
break;
case 3:
/*int*/
value = GenerateNumber(int.MaxValue,int.MinValue);
Console.WriteLine(value);
if(intTemp == 1)
{
Console.WriteLine("Please enter a value that matches the format:");
UserValue = Console.Readline();
if(UserValue => int.MinValue && UserValue =< int.MaxValue)
{
Console.WriteLine("CORRECT!");
}
else
{
Console.WriteLine("WRONG!");
}
}
break;
case 4:
/*uint*/
value = GenerateNumber(uint.MaxValue,uint.MinValue);
Console.WriteLine(value);
if(intTemp == 1)
{
Console.WriteLine("Please enter a value that matches the format:");
UserValue = Console.Readline();
if(UserValue => uint.MinValue && UserValue =< uint.MaxValue)
{
Console.WriteLine("CORRECT!");
}
else
{
Console.WriteLine("WRONG!");
}
}
break;
case 5:
/*short*/
value = GenerateNumber(short.MaxValue,short.MinValue);
Console.WriteLine(value);
if(intTemp == 1)
{
Console.WriteLine("Please enter a value that matches the format:");
UserValue = Console.Readline();
if(UserValue => short.MinValue && UserValue =< short.MaxValue)
{
Console.WriteLine("CORRECT!");
}
else
{
Console.WriteLine("WRONG!");
}
}
break;
case 6:
/*ushort*/
value = GenerateNumber(ushort.MaxValue,ushort.MinValue);
Console.WriteLine(value);
if(intTemp == 1)
{
Console.WriteLine("Please enter a value that matches the format:");
UserValue = Console.Readline();
if(UserValue => ushort.MinValue && UserValue =< ushort.MaxValue)
{
Console.WriteLine("CORRECT!");
}
else
{
Console.WriteLine("WRONG!");
}
}
break;
case 7:
/*long*/
value = GenerateNumber(long.MaxValue,long.MinValue);
Console.WriteLine(value);
if(intTemp == 1)
{
Console.WriteLine("Please enter a value that matches the format:");
UserValue = Console.Readline();
if(UserValue => long.MinValue && UserValue =< long.MaxValue)
{
Console.WriteLine("CORRECT!");
}
else
{
Console.WriteLine("WRONG!");
}
}
break;
case 8:
/*ulong*/
value = GenerateNumber(ulong.MaxValue,ulong.MinValue);
Console.WriteLine(value);
if(UserValue => ulong.MinValue && UserValue =< ulong.MaxValue)
{
Console.WriteLine("CORRECT!");
}
else
{
Console.WriteLine("WRONG!");
}
}
break;
case 9:
/*char*/
value = GenerateNumber(char.MaxValue,char.MinValue);
Console.WriteLine(value);
if(intTemp == 1)
{
Console.WriteLine("Please enter a value that matches the format:");
UserValue = Console.Readline();
if(UserValue => char.MinValue && UserValue =< char.MaxValue)
{
Console.WriteLine("CORRECT!");
}
else
{
Console.WriteLine("WRONG!");
}
}
break;
case 10:
/*float*/
value = GenerateNumber(float.MaxValue,float.MinValue);
Console.WriteLine(value);
if(intTemp == 1)
{
Console.WriteLine("Please enter a value that matches the format:");
UserValue = Console.Readline();
if(UserValue => float.MinValue && UserValue =< float.MaxValue)
{
Console.WriteLine("CORRECT!");
}
else
{
Console.WriteLine("WRONG!");
}
}
break;
case 11:
/*double*/
value = GenerateNumber(double.MaxValue,double.MinValue);
Console.WriteLine(value);
if(intTemp == 1)
{
Console.WriteLine("Please enter a value that matches the format:");
UserValue = Console.Readline();
if(UserValue => double.MinValue && UserValue =< double.MaxValue)
{
Console.WriteLine("CORRECT!");
}
else
{
Console.WriteLine("WRONG!");
}
}
break;
case 12:
/*decimal*/
value = GenerateNumber(decimal.MaxValue,decimal.MinValue);
Console.WriteLine(value);
break;
case 13:
/*string*/
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var stringChars = new char[8];
var random = new Random();

for (int i = 0; i < stringChars.Length; i++)
{
stringChars[i] = chars[random.Next(chars.Length)];
}
var finalString = new String(stringChars);
Console.WriteLine(finalString);
if(intTemp == 1)
{
Console.WriteLine("Please enter a value that matches the format:");
UserValue = Console.Readline();
if(UserValue => string.MinValue && UserValue =< string.MaxValue)
{
Console.WriteLine("CORRECT!");
}
else
{
Console.WriteLine("WRONG!");
}
}
break;
}
}
}


}



asked 37 secs ago







Hello Can someone let me know why this code won't compile

Aucun commentaire:

Enregistrer un commentaire