Need a little help with my Homework :(

Def need some help with this code :(
The goal of this assignment is to create several arithmetic tables for the user. This will be separated into several segments.

Task 1 - Menu system. (7 points)
The first task is to create a menu system that will drive the program. The user will be able to create an arithmetic table for each of the four basic operators (+,-,*,/). Give the user a menu to choose which of these operators they wish to do.

Example:

Welcome to Math Study guide.
Which arithmetic table would you like to see?

1) Addition
2) Subtraction
3) Multiplication
4) Division
X) Exit the program
>>:

This menu should loop while the user enters invalid responses. The menu loop should stop when the user either enters a value to quit (-1 for example, or a character such as 'X') or a valid input.

Note: You can choose your method of input. If you want to process strings or characters go ahead!

Task 2 - Further input and If-Else If-Else or Switch to handle menu choice (6 points) Now you will get the boundaries for the table.

After getting the menu choice - regardless of which option is chosen you should now get the boundaries for the tables. You will get two numbers since you will be creating an X by Y (2 dimensional) table. Prompt the user for their choices. You should get the input in the format of "x y" (two number with a space in between).

Hint: input doesn't require a prompt to work syntactically, and numerical input reads numbers until it sees any whitespace

If either value is <= 0 tell the user that this is invalid and get the input again.

Example:

Enter the dimensions of the arithmetic table (x y):
Create either an If-Else If-Else chain or use a Switch Statement to handle the menu option.

Create this structure first before filling in the details (part 3).

Task 3 - Generate the appropriate arithmetic table (7 points)
For each math of the math operators generate the appropriate table from 1 to the value provided by the user performing the operator of choice.



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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  #include <iostream>
using namespace std;

int main()
{
    char input;
    int x=0;
    int y=0;
    //Display Welcome message
    cout << "Welcome to the Math Study Guide!\n";
    cout << "Which arithmetic table would you like to see?!\n"; // add newline on end
    
    do
    {
        cout << "1 Addition\n";
        cout << "2 Substraction\n";
        cout << "3 Multiplication\n";
        cout << "4 Division\n";
        cout << "X Exit the program\n";
        cout << ">>\n";
        cin >> input;
        
        if (input == 'X'){
            return 0;
        }
        
    }while(!(input == '1' || input == '2' || input == '3' || input == '4'));
    // check if the input is valid or not, if it isn't , repeat
    
    
    while (1){
        cout << "Choose x: \n";
        cin >> x;
        cout << "Choose y: \n";
        cin >> y;
        
        if (x <= 0 || y <= 0){
            cout << "You have entered an invalid dimension. Please enter a value greater than 0 for both dimensions.\n";
            cout << "Please enter the dimensions of the table (eg: 4 4): \n";
        }
        else{
            break; // break out of loop
        }
    }
} // ending int main ()
    switch (input)
{
    case '1':
        // display the table for addition
        println("\nYou have selected addition with a table size of " + x + " by " + y + ":");
        for(double i = 1; i <= x; i++)
        {
            for(double j = 1; j <= y; j++)
            {
                cout("%8.2f", (i + j));
            }
            printf();
        }
        break;
        
    case '2':
        // display the table for subtraction
        println("\nYou have selected subtraction with a table size of " + x + " by " + y + ":");
        for(double i = 1; i <= x; i++)
        {
            for(double j = 1; j <= y; j++)
            {
                printf("%8.2f", (i - j));
            }
            println();
        }
        break;
        
    case '3':
        // display the table for multiplication
        println("\nYou have selected multiplication with a table size of " + x + " by " + y + ":");
        for(double i = 1; i <= x; i++)
        {
            for(double j = 1; j <= y; j++)
            {
                printf("%8.2f", (i * j));
            }
            println();
        }
        break;
        
    case '4':
        // display the table for division
        println("\nYou have selected division with a table size of " + x + " by " + y + ":");
        for(double i = 1; i <= x; i++)
        {
            for(double j = 1; j <= y; j++)
            {
                printf("%8.2f", (i / j));
            }
            println();
        }
        break;
        
    case 'X':
        // display the exit message
        println("Thank you");
        break;
        
    default:
        // display the error message
        println("That is an invalid selection! Please choose 1-4 or X to exit.");

while(response != 'X');
 // end of main method
} // end of Assignment3 class 
Last edited on
Please state the assignment and what the code is doing or not doing. But don't expect me to give you the answer. I'll help you, not spoon-feed you.
Hello unknown3112,

As it is now your code will not even compile. There are many problems with the code. First you are mixing C code in a C++ program. You have not included any header files to work with C code.

If you have learned about functions I would put the menu in a function that returns the menu choice.

Line 45 is the closing brace for the main function which puts the switch outside of main and it is never reached. Line 45 should be at line 108.

On line 55 you are mixing C++ cout with C style format and that will not work. Also the cout statement is written wrong.

Lines 50, 68, 81, 94 and 102 will not work without including the "stdio.h" header file.

Lines 69, 89, 95, 102, 108, 115, 121 and 121 println is not part of C or C++.

I do not believe the for loops in the case statements need to be "double" "int" should work fine.

Line 109 not sure what the while statement is for, but the variable "response" is not even defined anywhere that I found. Also "response" is never changed anywhere in the program. All it does is produce an endless loop that locks up the program.

Hope that helps,

Andy
Topic archived. No new replies allowed.