Question

In: Computer Science

Every time I run this code I get two errors. It's wrote in C# and I...

Every time I run this code I get two errors. It's wrote in C# and I can't figure out what I'm missing or why it's not running properly. These are two separate classes but are for the same project.

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RecursiveMethod
{
    class Program
    {
        static bool ordering = true;
        static string str;
        static int quantity = 0;
        static string Invoic = string.Empty;
        static double itemPrice;
        static double totalCost = 0;
        static void Main(string[] args)
        {
            int menuOption;
            int Item = 0;

            Console.WriteLine("Enter your FirstName"); //First Name 
            string sFirstName = Console.ReadLine();

            Console.WriteLine("Enter your LastName"); //Last Name
            string sLastName = Console.ReadLine();

            Console.WriteLine("Enter your ID"); //Last Name
            string sStudentID = Console.ReadLine();

            str = sFirstName + sLastName;

            //Call this methos to show student info staring of the programm
            displayStudentInfo(str,sStudentID);

            //display your message function
            displayMessage(str);


            string invoice = string.Empty;
            while (ordering)
            {
                Console.WriteLine("Enter your item");
                menuOption = Convert.ToInt32(Console.ReadLine());
                double cost;
                
                switch (menuOption)
                {
                    case 1:
                        Item = 1;
                        ProgressLogic.addItem(1, invoice, out Invoic, out quantity,out itemPrice);
                        invoice = Invoic;
                        cost = displayTotal(itemPrice, quantity);
                        break;
                    case 2:
                        Item = 2;
                        ProgressLogic.addItem(2, invoice, out Invoic, out quantity, out itemPrice);
                        invoice = Invoic;
                        cost = displayTotal(itemPrice, quantity);
                        break;
                    case 0:                       
                        done(totalCost, invoice);
                        Console.ReadLine();
                        break;
                    default:
                        Console.WriteLine("Invalid Option");
                        break;
                }
            }

        }

        /// <summary>
        /// Show the Message
        /// </summary>
        /// <param name="str"></param>
        public static void displayMessage(string str)
        {
            Console.WriteLine("Welcome " + str + " to dave onlines coffee shop");
        }

        /// <summary>
        /// Show the Student Info
        /// </summary>
        /// <param name="studentFullName"></param>
        /// <param name="iStudentID"></param>
        public static void displayStudentInfo(string studentFullName, string iStudentID)
        {
            Console.WriteLine("Welcome " + studentFullName + " Student ID - " + iStudentID);
            Console.WriteLine("Please choose the following Products code. Enter 0 to Exit");
            Console.WriteLine("Product 1 kona bled -> $14.95");
            Console.WriteLine("Product 2 cafe verona -> $9.95");
        }

        /// <summary>
        /// Done Method to show the information based on the total cost calculations
        /// </summary>
        /// <param name="totalCost"></param>
        public static void done(double totalCost, string strInvoice)
        {
            ordering = false;
            Console.WriteLine("Customer Name");
            Console.WriteLine("\n"+ strInvoice);
            Console.WriteLine("\n"+"Total Cost"+ totalCost + "$");
        }

        /// <summary>
        /// Disaply the total cost
        /// </summary>
        /// <param name="itemPrice"></param>
        /// <param name="quant"></param>
        /// <returns></returns>
        public static double displayTotal(double itemPrice, double quant)
        {
            double cost = (itemPrice * quant);
            totalCost += cost;
            return totalCost;
        }
    }
}
using Microsoft.SqlServer.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RecursiveMethod
{
    public class ProgressLogic
    {
       
       //This method will do the programming logic and will return the calculations in the out parameter       
        public static double addItem(int item, string oldInvoiceString, out string Invoice, out int quantity, out double itemPrice) {
           //we need to initialize the out parameters first so definitily it will some value instead of nothig
           //ow it will show error
            Invoice = "";
            quantity = 0;
            itemPrice = 00.00;
            
            if (item == 1) {
                itemPrice = 14.95;
                Console.WriteLine("Enter Quantity"); //Last Name
                quantity = Convert.ToInt32( Console.ReadLine());
                Invoice = oldInvoiceString + " Product 1 kona Blend -> $" + itemPrice + " * " + quantity + " = " + itemPrice * quantity + "\n";
            }

            if (item == 2)
            {
                itemPrice = 9.95;
                Console.WriteLine("Enter Quantity"); //Last Name
                quantity = Convert.ToInt32(Console.ReadLine());
                Invoice = oldInvoiceString + "Product 2 cafe verona-> $" + itemPrice + " * " + quantity + " = " + itemPrice * quantity + "\n";
            }

            return itemPrice;
        }

        
    }
}

Solutions

Expert Solution

Run it Now.. In the same file..Just copy paste... I'm attaching a result from the o/p

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RecursiveMethod
{
    class Program
    {
        static bool ordering = true;
        static string str;
        static int quantity = 0;
        static string Invoic = string.Empty;
        static double itemPrice;
        static double totalCost = 0;
        
        public class ProgressLogic
    {
       
       //This method will do the programming logic and will return the calculations in the out parameter       
        public static double addItem(int item, string oldInvoiceString, out string Invoice, out int quantity, out double itemPrice) {
           //we need to initialize the out parameters first so definitily it will some value instead of nothig
           //ow it will show error
            Invoice = "";
            quantity = 0;
            itemPrice = 00.00;
            
            if (item == 1) {
                itemPrice = 14.95;
                Console.WriteLine("Enter Quantity"); //Last Name
                quantity = Convert.ToInt32( Console.ReadLine());
                Invoice = oldInvoiceString + " Product 1 kona Blend -> $" + itemPrice + " * " + quantity + " = " + itemPrice * quantity + "\n";
            }

            if (item == 2)
            {
                itemPrice = 9.95;
                Console.WriteLine("Enter Quantity"); //Last Name
                quantity = Convert.ToInt32(Console.ReadLine());
                Invoice = oldInvoiceString + "Product 2 cafe verona-> $" + itemPrice + " * " + quantity + " = " + itemPrice * quantity + "\n";
            }

            return itemPrice;
        }

        
    }
        
        
        
        
        
        static void Main(string[] args)
        {
            int menuOption;
            int Item = 0;

            Console.WriteLine("Enter your FirstName"); //First Name 
            string sFirstName = Console.ReadLine();

            Console.WriteLine("Enter your LastName"); //Last Name
            string sLastName = Console.ReadLine();

            Console.WriteLine("Enter your ID"); //Last Name
            string sStudentID = Console.ReadLine();

            str = sFirstName + sLastName;

            //Call this methos to show student info staring of the programm
            displayStudentInfo(str,sStudentID);

            //display your message function
            displayMessage(str);


            string invoice = string.Empty;
            while (ordering)
            {
                Console.WriteLine("Enter your item");
                menuOption = Convert.ToInt32(Console.ReadLine());
                double cost;
                
                switch (menuOption)
                {
                    case 1:
                        Item = 1;
                        ProgressLogic.addItem(1, invoice, out Invoic, out quantity,out itemPrice);
                        invoice = Invoic;
                        cost = displayTotal(itemPrice, quantity);
                        break;
                    case 2:
                        Item = 2;
                        ProgressLogic.addItem(2, invoice, out Invoic, out quantity, out itemPrice);
                        invoice = Invoic;
                        cost = displayTotal(itemPrice, quantity);
                        break;
                    case 0:                       
                        done(totalCost, invoice);
                        Console.ReadLine();
                        break;
                    default:
                        Console.WriteLine("Invalid Option");
                        break;
                }
            }

        }

        /// <summary>
        /// Show the Message
        /// </summary>
        /// <param name="str"></param>
        public static void displayMessage(string str)
        {
            Console.WriteLine("Welcome " + str + " to dave onlines coffee shop");
        }

        /// <summary>
        /// Show the Student Info
        /// </summary>
        /// <param name="studentFullName"></param>
        /// <param name="iStudentID"></param>
        public static void displayStudentInfo(string studentFullName, string iStudentID)
        {
            Console.WriteLine("Welcome " + studentFullName + " Student ID - " + iStudentID);
            Console.WriteLine("Please choose the following Products code. Enter 0 to Exit");
            Console.WriteLine("Product 1 kona bled -> $14.95");
            Console.WriteLine("Product 2 cafe verona -> $9.95");
        }

        /// <summary>
        /// Done Method to show the information based on the total cost calculations
        /// </summary>
        /// <param name="totalCost"></param>
        public static void done(double totalCost, string strInvoice)
        {
            ordering = false;
            Console.WriteLine("Customer Name");
            Console.WriteLine("\n"+ strInvoice);
            Console.WriteLine("\n"+"Total Cost"+ totalCost + "$");
        }

        /// <summary>
        /// Disaply the total cost
        /// </summary>
        /// <param name="itemPrice"></param>
        /// <param name="quant"></param>
        /// <returns></returns>
        public static double displayTotal(double itemPrice, double quant)
        {
            double cost = (itemPrice * quant);
            totalCost += cost;
            return totalCost;
        }
    }
}
// using Microsoft.SqlServer.Server;
// using System;
// using System.Collections.Generic;
// using System.Linq;
// using System.Text;
// using System.Threading.Tasks;

// namespace RecursiveMethod
// {
//     public class ProgressLogic
//     {
       
//       //This method will do the programming logic and will return the calculations in the out parameter       
//         public static double addItem(int item, string oldInvoiceString, out string Invoice, out int quantity, out double itemPrice) {
//           //we need to initialize the out parameters first so definitily it will some value instead of nothig
//           //ow it will show error
//             Invoice = "";
//             quantity = 0;
//             itemPrice = 00.00;
            
//             if (item == 1) {
//                 itemPrice = 14.95;
//                 Console.WriteLine("Enter Quantity"); //Last Name
//                 quantity = Convert.ToInt32( Console.ReadLine());
//                 Invoice = oldInvoiceString + " Product 1 kona Blend -> $" + itemPrice + " * " + quantity + " = " + itemPrice * quantity + "\n";
//             }

//             if (item == 2)
//             {
//                 itemPrice = 9.95;
//                 Console.WriteLine("Enter Quantity"); //Last Name
//                 quantity = Convert.ToInt32(Console.ReadLine());
//                 Invoice = oldInvoiceString + "Product 2 cafe verona-> $" + itemPrice + " * " + quantity + " = " + itemPrice * quantity + "\n";
//             }

//             return itemPrice;
//         }

        
//     }
// }

Feel free to ask ?


Related Solutions

There are logical and run time errors in the code, as well as compilation errors. **...
There are logical and run time errors in the code, as well as compilation errors. ** Your objective is get the code to run, fix any bugs in the code and ** place validation needed to prevent any memory issues. Each function has a ** description of what it does next to its prototype. ** When you find a problem, fix it in the code and note it in this header comment below. ** Please note each problem you find...
There are two errors in this code. Identify the errors and give the correct code that...
There are two errors in this code. Identify the errors and give the correct code that will make the program to display the following output: Rectangle: height 2.0 width 4.0 Area of the Rectangle is 8.0 ----- public interface Shape { public double getArea(); } class Rectangle implements Shape { double height; double width; public Rectangle(double height, double width) { this.height=height; this.width=width; } public double getArea() { return height*width; } public String toString() { return "Rectangle: height "+height+" width "+width;...
Hi! I wrote two function to get count cluster of char in a string , charFreq(),...
Hi! I wrote two function to get count cluster of char in a string , charFreq(), and an other one which iterate through a vector line by line looking for last element on each line, last(). The problem is, after appending all chars in a string and try to count clusters of values in that string, I get seg fault. I feel like my logic behind is ok, but I am not sure what I did wrong. Can someone help...
I get the following errors when I type the code #include <iostream> #include <string.h> #include <bitset>...
I get the following errors when I type the code #include <iostream> #include <string.h> #include <bitset> #include <math.h> #define IS_INTEGRAL(T) typename std::enable_if< std::is_integral<T>::value >::type* = 0 using namespace std; template<class T> std::string inttobits1(T byte, IS_INTEGRAL(T)) { std::bitset<sizeof(T)* CHAR_BIT> bs(byte); return bs.to_string(); } int bitstoint1(string bits) { int value; for (int x = 0, y = bits.length() - 1;x < 8 && x < bits.length();x++) { int val = atoi(bits.substr(y, 1).c_str()); value += (int)val * pow(2, x); } return value; }...
Every time I attempt to execute this, I get an inputmismatchexception, which looks like this: Oops!...
Every time I attempt to execute this, I get an inputmismatchexception, which looks like this: Oops! Read Exception: java.util.InputMismatchExceptionInitial input: Input sorted by grade Input sorted selection This is my code. import java.util.*;   import java.io.*; import java.io.PrintStream; public class jack { PrintStream prt = System.out; int n; int i; int j; double grade[]; String name[]; jack() { try { Scanner inf = new Scanner(System.in); n=inf.nextInt(); inf.nextLine(); grade=new double[n]; name = new String[n]; for (int i=0; i<n; i++){ name[i] = inf.next();...
I cannot get this code to run on my python compiler. It gives me an expected...
I cannot get this code to run on my python compiler. It gives me an expected an indent block message. I do not know what is going on. #ask why this is now happenning. (Create employee description) class employee: def__init__(self, name, employee_id, department, title): self.name = name self.employee_id = employee_id self.department = department self.title = title def __str__(self): return '{} , id={}, is in {} and is a {}.'.format(self.name, self.employee_id, self.department, self.title)    def main(): # Create employee list emp1...
Please do it in C++. Please comment on the code, and comments detail the run time...
Please do it in C++. Please comment on the code, and comments detail the run time in terms of total operations and Big O complexities. 1. Implement a class, SubstitutionCipher, with a constructor that takes a string with the 26 uppercase letters in an arbitrary order and uses that as the encoder for a cipher (that is, A is mapped to the first character of the parameter, B is mapped to the second, and so on.) Please derive the decoding...
When I wrote this code in the Eclipse program, I did not see a output .....
When I wrote this code in the Eclipse program, I did not see a output .. Why? _______ public class AClass { private int u ; private int v ; public void print(){ } public void set ( int x , int y ) { } public AClass { } public AClass ( int x , int y ) { } } class BClass extends AClass { private int w ; public void print() { System.out.println (" u + v...
I wrote this code and just realized I need to put it into at least 6...
I wrote this code and just realized I need to put it into at least 6 different functions and I don't know how. No specific ones but recommended is: Read Data, Calculate Installation Price, Calculate Subtotal, Calculate Total, Print -> 1) Print Measurements & 2) Print Charges. Can somebody help? #include <stdio.h> // Function Declarations int length, width, area, discount; int main () { // Local Declarations double price, cost, charge, laborCharge, installed, amtDiscount, subtotal, amtTax, total; const double tax...
what is the calculated the average code using C++ Having a hard time trying to get...
what is the calculated the average code using C++ Having a hard time trying to get the float average.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT