Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › C# Second Assignment quick easy help
New Posts  All Forums:Forum Nav:

C# Second Assignment quick easy help

post #1 of 7
Thread Starter 
Soooo, second assignment, online class, question is

Quote:
Write a program that computes the average of five exam scores. declare and perform a compile-time initilization wit hteh five values. Use a constant to dfine the number of scores. Print all scores and the average value formatted with no digits to the right of the decimal. rerun the application with different values.


And im having issues, get a few errors, but mainly the double thing im confused out of my mind about.
Code:

using System;

namespace QuizAverages
{
    class HereComeTheAverages
    {
        static void Main()
    {
        const int NumberOfQuizzesInputtttted = 5;
        int QuizOne = 60,
            QuizTwo = 80,
            QuizThree = 75,
            QuizFour = 0,
            QuizFive = 35;
      
                double AverageGradeComesTo,      //wth does double mean and what am i supposed to put here? ARGH!

                QuizOne + QuizTwo + QuizThree + QuizFour + QuizFive / 5 = AverageGradeComesTo
                    Console.WriteLine("The Average of the five input grades," Print QuizOne "," Print QuizTwo "," Print QuizThree "," Print QuizFour ", and" Print QuizFive "is" AverageGradeComesTo);
                        Console.Read();
      }
      }
}

Can anyone shed me some light pretty please biggrin.gif
P50
(15 items)
 
   
CPUGraphicsRAMHard Drive
Intel Core i7-6700HQ NVIDIA Quadro M1000M 4GB Gskill 32gb 4x8gb DDR4 2300mhz Samsung 850 PRO - 1TB SSD m2 
Hard DriveOptical DriveOSOS
Seagate 2TB w/ 128MB Cache (ST2000LM007) Pioneer External USB-C Blu-Ray Burner Fedora 25 Win 10 LTSB 
MonitorMonitorMonitorPower
15.6" 1920x1080 IPS BenQ GL2460HM 24" LED BenQ GL2460HM 24" LED Lenovo 170w Power adapter 
MouseOther
MX-580 or Razor bluetooth something or other Docking station 40A50230US 
CPUMotherboardRAMHard Drive
i7 3770k BIOSTAR TH67+ 32gb 4x8 Corsair Vengence 1600 1x 256gb m2 
Hard DriveOSPowerCase
6x Seagate 2.5" 3tb > ~8.5tb raid 10 OpenSuse Seasonic G 550w Silverstone SG11B 
Other
Raid card 
  hide details  
Reply
P50
(15 items)
 
   
CPUGraphicsRAMHard Drive
Intel Core i7-6700HQ NVIDIA Quadro M1000M 4GB Gskill 32gb 4x8gb DDR4 2300mhz Samsung 850 PRO - 1TB SSD m2 
Hard DriveOptical DriveOSOS
Seagate 2TB w/ 128MB Cache (ST2000LM007) Pioneer External USB-C Blu-Ray Burner Fedora 25 Win 10 LTSB 
MonitorMonitorMonitorPower
15.6" 1920x1080 IPS BenQ GL2460HM 24" LED BenQ GL2460HM 24" LED Lenovo 170w Power adapter 
MouseOther
MX-580 or Razor bluetooth something or other Docking station 40A50230US 
CPUMotherboardRAMHard Drive
i7 3770k BIOSTAR TH67+ 32gb 4x8 Corsair Vengence 1600 1x 256gb m2 
Hard DriveOSPowerCase
6x Seagate 2.5" 3tb > ~8.5tb raid 10 OpenSuse Seasonic G 550w Silverstone SG11B 
Other
Raid card 
  hide details  
Reply
post #2 of 7
"double" is like a "float", a number.
Unlike Integers, double can have two digits right of the decimal (float can have many more).

Doubles are used for accurate calculations, where integers are not precise enough (for example - calculating average scores), and floats are overkill.

Conversion to int happens like this:
int theValueToConvert = Convert.ToInt32(doubleValue);
My Rig
(14 items)
 
Ex-wife's Rig
(15 items)
 
 
CPUMotherboardGraphicsRAM
Core i5 4460 AsRock H81M-DG4 Sapphire Rx470 Platinum KVR 1600 16Gb 
Hard DriveHard DriveCoolingOS
2x Seagate 3Tb Samsung 850 EVO 120 Scythe Ninja 3 Rev.B Windows 10 Pro 
MonitorKeyboardPowerCase
Fujitsu Siemens A17-2A Logitech K280e SuperFlower SF-550K12XP Thermaltake Versa H25 
MouseAudio
Logitech G402 Sony MDR XD150 
CPUMotherboardGraphicsRAM
Athlon 750K 4.0Ghz AsRock FM2A75 Pro4+ Sapphire R9 270X Dual-X Kingston 2x4Gb 1600 
Hard DriveHard DriveOptical DriveCooling
Samsung 850 EVO 120  Western Digital 320Gb LiteON DVD-RW CoolerMaster Hyper Z600 
OSMonitorKeyboardPower
Windows 7 Pro x64 Toshiba 32" FullHD TV Logitech FSP Hexa 550 
CaseMouse
DeLUX Logitech 
  hide details  
Reply
My Rig
(14 items)
 
Ex-wife's Rig
(15 items)
 
 
CPUMotherboardGraphicsRAM
Core i5 4460 AsRock H81M-DG4 Sapphire Rx470 Platinum KVR 1600 16Gb 
Hard DriveHard DriveCoolingOS
2x Seagate 3Tb Samsung 850 EVO 120 Scythe Ninja 3 Rev.B Windows 10 Pro 
MonitorKeyboardPowerCase
Fujitsu Siemens A17-2A Logitech K280e SuperFlower SF-550K12XP Thermaltake Versa H25 
MouseAudio
Logitech G402 Sony MDR XD150 
CPUMotherboardGraphicsRAM
Athlon 750K 4.0Ghz AsRock FM2A75 Pro4+ Sapphire R9 270X Dual-X Kingston 2x4Gb 1600 
Hard DriveHard DriveOptical DriveCooling
Samsung 850 EVO 120  Western Digital 320Gb LiteON DVD-RW CoolerMaster Hyper Z600 
OSMonitorKeyboardPower
Windows 7 Pro x64 Toshiba 32" FullHD TV Logitech FSP Hexa 550 
CaseMouse
DeLUX Logitech 
  hide details  
Reply
post #3 of 7
Then your next line is inverted. Should be:

AverageGradeComesTo = (QuizOne + QuizTwo + QuizThree + QuizFour + QuizFive) / 5;
My Rig
(14 items)
 
Ex-wife's Rig
(15 items)
 
 
CPUMotherboardGraphicsRAM
Core i5 4460 AsRock H81M-DG4 Sapphire Rx470 Platinum KVR 1600 16Gb 
Hard DriveHard DriveCoolingOS
2x Seagate 3Tb Samsung 850 EVO 120 Scythe Ninja 3 Rev.B Windows 10 Pro 
MonitorKeyboardPowerCase
Fujitsu Siemens A17-2A Logitech K280e SuperFlower SF-550K12XP Thermaltake Versa H25 
MouseAudio
Logitech G402 Sony MDR XD150 
CPUMotherboardGraphicsRAM
Athlon 750K 4.0Ghz AsRock FM2A75 Pro4+ Sapphire R9 270X Dual-X Kingston 2x4Gb 1600 
Hard DriveHard DriveOptical DriveCooling
Samsung 850 EVO 120  Western Digital 320Gb LiteON DVD-RW CoolerMaster Hyper Z600 
OSMonitorKeyboardPower
Windows 7 Pro x64 Toshiba 32" FullHD TV Logitech FSP Hexa 550 
CaseMouse
DeLUX Logitech 
  hide details  
Reply
My Rig
(14 items)
 
Ex-wife's Rig
(15 items)
 
 
CPUMotherboardGraphicsRAM
Core i5 4460 AsRock H81M-DG4 Sapphire Rx470 Platinum KVR 1600 16Gb 
Hard DriveHard DriveCoolingOS
2x Seagate 3Tb Samsung 850 EVO 120 Scythe Ninja 3 Rev.B Windows 10 Pro 
MonitorKeyboardPowerCase
Fujitsu Siemens A17-2A Logitech K280e SuperFlower SF-550K12XP Thermaltake Versa H25 
MouseAudio
Logitech G402 Sony MDR XD150 
CPUMotherboardGraphicsRAM
Athlon 750K 4.0Ghz AsRock FM2A75 Pro4+ Sapphire R9 270X Dual-X Kingston 2x4Gb 1600 
Hard DriveHard DriveOptical DriveCooling
Samsung 850 EVO 120  Western Digital 320Gb LiteON DVD-RW CoolerMaster Hyper Z600 
OSMonitorKeyboardPower
Windows 7 Pro x64 Toshiba 32" FullHD TV Logitech FSP Hexa 550 
CaseMouse
DeLUX Logitech 
  hide details  
Reply
post #4 of 7
Quote:
Originally Posted by ronnin426850 View Post

"double" is like a "float", a number.
Unlike Integers, double can have two digits right of the decimal (float can have many more).
Doubles are used for accurate calculations, where integers are not precise enough (for example - calculating average scores), and floats are overkill.
Conversion to int happens like this:
int theValueToConvert = Convert.ToInt32(doubleValue);

in c# i believe you can just go
Code:
int var = int.parse(doublevalue);

To the OP
ive done a fair amount of c# programming but im not sure about this
Code:
QuizOne + QuizTwo + QuizThree + QuizFour + QuizFive / 5 = AverageGradeComesTo
i would write that as being
Code:
AverageGradeComesTo = (QuizOne + QuizTwo + QuizThree + QuizFour + QuizFive) / 5
Patawic's Rig
(14 items)
 
  
CPUMotherboardGraphicsRAM
Thuban 1055T Gigabyte 880GMA-UD2H GIGABYTE GeForce GTX 460 1GB OC Corsair 4gb 1333mhz DDR3 
Hard DriveOptical DriveCoolingOS
Samsung F4 LG CH10LS20 Bluray CoolerMaster Hyper Z600 Windows 7 
MonitorKeyboardPowerCase
Dell P4211H x 2 Logitech G110 OCZ 750W Fatal1ty HAF 912 
  hide details  
Reply
Patawic's Rig
(14 items)
 
  
CPUMotherboardGraphicsRAM
Thuban 1055T Gigabyte 880GMA-UD2H GIGABYTE GeForce GTX 460 1GB OC Corsair 4gb 1333mhz DDR3 
Hard DriveOptical DriveCoolingOS
Samsung F4 LG CH10LS20 Bluray CoolerMaster Hyper Z600 Windows 7 
MonitorKeyboardPowerCase
Dell P4211H x 2 Logitech G110 OCZ 750W Fatal1ty HAF 912 
  hide details  
Reply
post #5 of 7
a double is just a decimal value. Averagegradecomesto should be declared with a semicolon, not a comma. also when summing all the quiz scores use parentheses. not sure about writeline, but i don't think you're supposed to use a "print" statement. just combine seperate strings of text with "+"
post #6 of 7
Quote:
Originally Posted by ronnin426850 View Post

"double" is like a "float", a number.
Unlike Integers, double can have two digits right of the decimal (float can have many more).
Doubles are used for accurate calculations, where integers are not precise enough (for example - calculating average scores), and floats are overkill.
Conversion to int happens like this:
int theValueToConvert = Convert.ToInt32(doubleValue);

floats are actually less precise than doubles.
Quote:
The difference between the two is in the size of the numbers that they can hold. For float, you can have up to 7 digits in your number. For doubles, you can have up to 16 digits.

Source: http://www.homeandlearn.co.uk/csharp/csharp_s2p6.html
post #7 of 7
Quote:
Originally Posted by Mad Skillz View Post

floats are actually less precise than doubles.
Source: http://www.homeandlearn.co.uk/csharp/csharp_s2p6.html

My mistake. Been some time since I last coded tongue.gif
My Rig
(14 items)
 
Ex-wife's Rig
(15 items)
 
 
CPUMotherboardGraphicsRAM
Core i5 4460 AsRock H81M-DG4 Sapphire Rx470 Platinum KVR 1600 16Gb 
Hard DriveHard DriveCoolingOS
2x Seagate 3Tb Samsung 850 EVO 120 Scythe Ninja 3 Rev.B Windows 10 Pro 
MonitorKeyboardPowerCase
Fujitsu Siemens A17-2A Logitech K280e SuperFlower SF-550K12XP Thermaltake Versa H25 
MouseAudio
Logitech G402 Sony MDR XD150 
CPUMotherboardGraphicsRAM
Athlon 750K 4.0Ghz AsRock FM2A75 Pro4+ Sapphire R9 270X Dual-X Kingston 2x4Gb 1600 
Hard DriveHard DriveOptical DriveCooling
Samsung 850 EVO 120  Western Digital 320Gb LiteON DVD-RW CoolerMaster Hyper Z600 
OSMonitorKeyboardPower
Windows 7 Pro x64 Toshiba 32" FullHD TV Logitech FSP Hexa 550 
CaseMouse
DeLUX Logitech 
  hide details  
Reply
My Rig
(14 items)
 
Ex-wife's Rig
(15 items)
 
 
CPUMotherboardGraphicsRAM
Core i5 4460 AsRock H81M-DG4 Sapphire Rx470 Platinum KVR 1600 16Gb 
Hard DriveHard DriveCoolingOS
2x Seagate 3Tb Samsung 850 EVO 120 Scythe Ninja 3 Rev.B Windows 10 Pro 
MonitorKeyboardPowerCase
Fujitsu Siemens A17-2A Logitech K280e SuperFlower SF-550K12XP Thermaltake Versa H25 
MouseAudio
Logitech G402 Sony MDR XD150 
CPUMotherboardGraphicsRAM
Athlon 750K 4.0Ghz AsRock FM2A75 Pro4+ Sapphire R9 270X Dual-X Kingston 2x4Gb 1600 
Hard DriveHard DriveOptical DriveCooling
Samsung 850 EVO 120  Western Digital 320Gb LiteON DVD-RW CoolerMaster Hyper Z600 
OSMonitorKeyboardPower
Windows 7 Pro x64 Toshiba 32" FullHD TV Logitech FSP Hexa 550 
CaseMouse
DeLUX Logitech 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › C# Second Assignment quick easy help