Spanish equivalent parameter, need help with hw

I honestly don't understand what my teacher is asking me to do, but here's the question, maybe someone can comprehend what the question is, because I sure don't:

Review 4 Part 1: Write a function SpanishNum(int num) that displays the Spanish equivalent of it's int parameter that is in the range 1 to 5. To test this function, complete Review 4 Part 2, then print the complete program and turn in. :

1 uno
2 dos
3 tres
4 quattro
5 cinco

WAIT!! You are not done yet!!!!!!!!! Now write this main to test the SpanishNum() ->
Review 4 Part 2: Write a program where main() uses a for loop to display a table similar to the one above by calling SpanishNum() inside the loop. You do not need to cin() any data!!!!


I honestly have no clue what she's asking us to do.
Actually I figure that for the first part, I'm supposed to make the for something like (int a = 0; a > 5; a++) and make a switch making 1-5 cout a string.

but not sure about the 2nd
I think she's asking for something like this

1
2
3
4
5
6
7
8
9
....
void SpanishNum( int num )
{
   if(num==1)
      cout << "uno \n";
   else if(num==2)
      cout << "dos \n";
   ...
}
I am seeing a whole loop with if statements at the values of 1-2-3-4-5-6-7-8-9-10-20-30-40-50-60-70-80-90-100. To this will be a function that uses a switch or a set of if statements that convert a number to Spanish. For example.

While(num >0){
switch(num):
Case 1: std::cout << "UNO";
Num--;
Break;

Expand on that. Typing on my phone so sorry about that format.
Last edited on

@atropos (bane elemental?), it's asking for a for statement and that no user input is required, so I'm just assuming what I have below is what she's asking for..

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
#include<iostream>
using namespace std;
    //
    void SpanishNum();
//
int main(){
SpanishNum();
system("PAUSE");
}
//
void SpanishNum()
{
    for(int num = 0;  num <= 5;  ++num)
    {
        switch( num )
        {
            case 1:
                cout << num << " UNO \n";
                break;
            case 2:
                cout << num << " DOS \n";
                break;
            case 3:
                cout << num << " TRES \n";
                break;
            case 4:
                cout << num << " QUATRO \n";
                break;
            case 5:
                cout << num << " CINCO \n";
                break;
        }
    }
}
    
Move the loop inside SpanishNum() into main(), and add one "int" parameter to SpanishNum. In main(), pass the int used in the for loop to SpanishNum().
Oh, I thought part 1 question and part 2 question were separate.

Since your teacher wants you to call SpanishNum(int) from inside the for loop in main, you need to make a simple loop with a counter variable that ranges from 1 to 5, and for each pass of the loop, SpanishNum is called using the counter variable as the argument.
@ModShop

Like so?


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
#include<iostream>
using namespace std;
    //
    int SpanishNum(int num);
//
int main(){



for(int num = 0;  num <= 5;  ++num)
SpanishNum();



system("PAUSE");
}

//
int SpanishNum(int num)
{
    
    switch(num)
        {
            case 1:
                cout << num << " UNO \n";
                break;
            case 2:
                cout << num << " DOS \n";
                break;
            case 3:
                cout << num << " TRES \n";
                break;
            case 4:
                cout << num << " QUATRO \n";
                break;
            case 5:
                cout << num << " CINCO \n";
                break;
        }
        return(num);  
}
    
SpanishNum takes an int parameter num

Also, is SpanishNum(int) supposed to return a value, or print out the value itself?

Also,
@atropos (bane elemental?)
What?
Last edited on
@atropos, considering it's not a void, I feel like it's meant to return something, but it seems like the program could do the same thing without a return.

and nevermind, Atropos is the name of a hero from a game called DoTA :P
Since the function prints out the spanish words itself, it really has no need to return a value. I was just asking whether is was supposed to be void because in one post, you declare it as void SpanishNum(int); and in another itsint SpanishNum(int);
Topic archived. No new replies allowed.