Code isnt coming up with proper results :(

Write your question here.
Tasks:
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
        }
    }
switch (input)
{
    case '1':
        // display the table for addition
        cout << "\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++)
            {
                printf("%8.2f", (i + j));
            }
            
        }
        break;
        
    case '2':
        // display the table for subtraction
        cout << "\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++)
            {
                printf("%8.2f", (i - j));
            }
            
        }
        break;
        
    case '3':
        // display the table for multiplication
        cout << "\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++)
            {
                printf("%8.2f", (i * j));
            }
            
        }
        break;
        
    case '4':
        // display the table for division
        cout << "\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++)
            {
                printf("%8.2f", (i / j));
            }
            
        }
        break;
        
    case 'X':
        // display the exit message
        printf("Thank you");
        break;
        
    default:
        // display the error message
        printf("That is an invalid selection! Please choose 1-4 or X to exit.");

while(input != 'X');
}
}
Last edited on
Please don't post the same question multiple times. It's confusing and wastes peoples time.

See my response here:
http://www.cplusplus.com/forum/beginner/199304/#msg953190

Topic archived. No new replies allowed.