Hey guys im trying to work on this assignment i have. I am new to programming and this is my third assignment. Any help would be appreciated. Im not sure if im on the right track or not. here is what i have to do:

allow the user to enter a numeric answer to math problem and display their average score. The user will be allowed to answer as many math problems as they choose. After each entry we will display the current average score. The difference between the while loop and the do loop is the while loop tests a condition before running its code block where the do loop will execute its code block and then test a condition. Hence the names of pre-test loop for the while loop and post-test loop for the do loop. Since the do loop is a post-test loop, it will always execute its code block one time at a bare minimum.

these are the steps im trying to follow:

Inside the Main method block of code we are going to create a do loop. The advantage of a do loop is that it will always execute one time. In this application we will use that advantage to repeat several steps. The following steps are what we want to repeat:
1)Clear the console Display window. (This will keep the display from getting cluttered)
2)Use random object to get/store two random numbers for a math problem.
3)Randomly decide which math operator to use (+-*/)and store the symbol.
4)Display an application header and the math problem formatted.
5)Get the answer from the user and store it in a variable(i.e.“input”).
6)Convert variable(input)from a string to a double or integer.
7)Based on the math symbol calculate the correct answer using random numbers.
8)If user entry matches correct answer,add question point value to points earned total.
9)Add the question point value to the points possible total.
10)Display message with points earned, possible, and the average (earned/possible).
11)Display a message asking the user if they want to quit or get a new math problem.
12)Pause display and get the user response of quit or continue.

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

namespace MathProblems
{
    class Program
    {
        static void Main(string[] args)
        {
            string input;
            double totalPoints = 0;
            double userEarnedPoints = 0;
            double average = 0;
            int number1 = 0;
            int number2 = 0;
            int operators = 0;
            int answer = 0;
            double correctAnswer = 0;
            int mathProblem = 0;

            do
            {
                Console.Clear();
                Random number = new Random();
                number1 = number.Next(1, 31);
                number2 = number.Next(1, 31);
                operators = number.Next(1, 5);  // 1 = add, 2 = minus, 3 = multiply, 4 = divide
                Console.WriteLine("\tMath Problems\n");

                switch (operators)
                {
                    case 1:
                        answer = number1 + number2;
                        break;
                    case 2:
                        answer = number1 - number2;
                        break;
                    case 3:
                        answer = number1 * number2;
                        break;
                    case 4:
                        answer = number1 / number2;
                        break;
                    default:
                        break;


                }
                //if (operators == 1)
                //{
                //    Console.WriteLine("{0} + {1} = ", number1, number2);

                //}
                //else if (operators == 2)
                //{
                //    Console.WriteLine("{0} - {1} = ", number1, number2);
                //}
                //else if (operators == 3)
                //{
                //    Console.WriteLine("{0} * {1} = ", number1, number2);
                //}
                //else if (operators == 4)
                //{
                //    Console.WriteLine("{0} / {1} = ", number1, number2);
                //}
                //break;


            } while (true);

            Console.ReadLine();

Edited 2 Years Ago by kegs88

suppose to look like this

Edited 2 Years Ago by kegs88

Attachments Capture.PNG 113.03 KB

Im just not sure what to do next. when i run it, it keeps posting math problems over and over and not generating the actual math problems.

Of course these math problems wont generate themselves.
For starters, why don't you write the following after line 30?

Console.WriteLine();
mathProblem++;
Console.Write("Math problem {0}:", mathProblem);

Edited 2 Years Ago by ddanbe: typo

Comments
ok I did that but when i Run it why does it keep running over and over? i put Console.ReadLine(); but then it does not do the math problem

ok I did that but when i Run it, why does it keep running over and over? i put Console.ReadLine(); but then it does not do the math problem

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

namespace FranciscoAlatorreMathProblems5B
{
    class Program
    {
        static void Main(string[] args)
        {
            bool correct = true;
            string input;
            double totalPoints = 0;
            double userEarnedPoints = 0;
            double average = 0;
            int number1 = 0;
            int number2 = 0;
            int operators = 0;
            double answer = 0;
            double correctAnswer = 0;
            int mathProblem = 0;

            do
            {
                Console.Clear();
                Random number = new Random();
                number1 = number.Next(1, 31);
                number2 = number.Next(1, 31);
                operators = number.Next(1, 5);  // 1 = add, 2 = minus, 3 = multiply, 4 = divide
                Console.WriteLine("\tMath Problems\n");
                Console.WriteLine();
                mathProblem++;
                Console.Write("Math problem {0}:", mathProblem);


                switch (operators)
                {
                    case 1:

                       answer = number1 + number2;
                        Console.WriteLine("{0} + {1} = ", number1, number2);
                        break;
                    case 2:
                        answer = number1 - number2;
                        Console.WriteLine("{0} - {1} = ", number1, number2);
                        break;
                    case 3:
                        answer = number1 * number2;
                        Console.WriteLine("{0} * {1} = ", number1, number2);
                        break;
                    case 4:
                        answer = number1 / number2;
                        Console.WriteLine("{0} / {1} = ", number1, number2);
                        break;
                    default:
                        break;

                Console.ReadLine();

                }



            } while (true);

            Console.ReadLine();

For the moment your readline is inside the switch statement. Due to the breaks in it, it will never be executed. Try to put it on line 36. But that is not important for the moment. You first have to construct a math problem with the data you got from your random functions and print it out with write or writelines. Could you at least try to do that? Success!

Move Console.ReadLine(); inside the loop so that it pauses between loop iterations.

      ...
Console.ReadLine();

} while (true);
      ...

Add some WriteLine statements (for debugging).

           ...
number1 = number.Next(1, 31);
number2 = number.Next(1, 31);
operators = number.Next(1, 5);  // 1 = add, 2 = minus, 3 = multiply, 4 = divide

Console.WriteLine("number1: " + number1); //debugging
Console.WriteLine("number2: " + number2); //debugging
Console.WriteLine("operators: " + operators); //debugging
Console.WriteLine(); //debugging

Console.WriteLine("\tMath Problems\n");
            ...

Continue writing code to solve the rest of your identified problems:

  • Allow user to enter a numeric answer to the math problem
  • Display average score
  • Items: 4, 5, 6, 8, 9, 10, 11 that you identified above.

Edited 2 Years Ago by cgeier

On line 66 of your last code you have: } while (true);
Try this:

  Console.WriteLine();
  Console.WriteLine("Press any key for next math problem or 'Q' to quit");
  keyInfo = Console.ReadKey();
} while (keyInfo.Key != ConsoleKey.Q);
This article has been dead for over six months. Start a new discussion instead.