Please Help Void function

//Chapter 5 Review 4
//Aurora Van De Water
#include <iostream>
using namespace std;


void SpanishNum();

void SpanishNum(int num)
{
while (num==1){
cout << num << "uno"<<endl;
}
while(num==2){
cout << num << "dos"<<endl;
}
while(num==3){
cout << num << "tres"<<endl;
}
while(num==4){
cout << num << "quatro"<<endl;
}
while(num==5){
cout << num << "cinco"<<endl;
}
}
int main(){
int num=0;
for(int num = 0; num <= 5; num++)
SpanishNum(num);
return(0);
}
Is there a question here?
the problem you have is that as soon as you pass num = 1 to that function num is never changed again and so you get stuck in an infinite loop. Instead of using while loops use a switch statement like so:

1
2
3
4
5
6
7
void SpanishNum(int num)
    switch(num)
    {
    case 1:
        cout << num << "uno" << endl;
        break;
    } //etc... 
use if instead of while
Topic archived. No new replies allowed.