No title

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Midterm2602Solution_Methods
{
    class Program
    {
        static void Main(string[] args)
        {
            ConfingureConsole();

            double coinValue;  // hold a coins value
            double totalValue = 0;  // initialize accumulator
            int counter = 0;  // initialize accumulator

            // print title
            Console.WriteLine("\tCoin Worth Application\n");

            // prompt for name
            Console.Write("Enter your name: ");
            string name = Console.ReadLine();

            // initialize condition variable for loop
            Console.Write("Do you want to enter coin (Yes/No)");
            string choice = Console.ReadLine();

            while( choice == "Yes" ) // 2 - check the condition
            {
                // 3 - work
                Console.Write("Enter weight: ");
                double weight = double.Parse(Console.ReadLine());

                Console.Write("Is it gold? (Y/N): ");
                string isGold = Console.ReadLine();

                // conditional logic for determining coin price
                if( isGold == "Y" )
                {
                    coinValue = weight * 29.02;
                    counter++;
                }
                else
                {
                    coinValue = weight * 0.55;
                }

                // totalValue = totalValue + coinValue;
                totalValue += coinValue;

                // Display coin value
                Console.WriteLine("This coin is worth {0:C}", coinValue);

                // 4 -update the condition variable
                Console.Write("Do you want to enter coin (Yes/No)");
                choice = Console.ReadLine();
            }

            Console.WriteLine("Results for {0}", name);
            Console.WriteLine("The value of all coins is {0:C}", totalValue);
            Console.WriteLine("You entered {0} gold coins", counter);

            Console.ReadKey(); // pause the screen;
        }


        // configureconsole method -- no input parameters or return value
        static void ConfingureConsole()
        {
            Console.Title = "Midterm solution";
            Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Black;
            Console.Clear(); // flush the colors over the console
        }

        // string prompt method - takes string as parameter, returns string result
        static string StringPrompt( string s )
        {
            Console.Write(s);
            string result = Console.ReadLine();  
            return result;
            // return Console.ReadLine();  // condensed example
        }


    }
}