I have to make a college program whose main purpose is another one, but in one of the program steps, I need to pass two whole random numbers from 0 to 9 to their extensive written forms, in string . I wrote a few snippets of code that would do that, but I did not have much success.
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
int main(){
int i=0, rand1, rand2;
char num1[7], num2[7];
printf("Bem vindo! Pronto pra começar? Vamos la!");
srand(time(NULL));
while (i<10){
rand1=rand()%10;
rand2=rand()%10;
switch (rand1){
case 0:
num1 = "ZERO";
case 1:
num1 = "UM";
case 2:
num1 = "DOIS";
case 3:
num1 = "TRES";
case 4:
num1 = "QUATRO"
case 5:
num1 = "CINCO";
case 6:
num1 = "SEIS";
case 7:
num1 = "SETE";
case 8:
num1 = "OITO";
case 9:
num1 = "NOVE";
}
switch (rand2){
case 0:
num2 = "ZERO";
case 1:
num2 = "UM";
case 2:
num2 = "DOIS";
case 3:
num2 = "TRES";
case 4:
num2 = "QUATRO"
case 5:
num2 = "CINCO";
case 6:
num2 = "SEIS";
case 7:
num2 = "SETE";
case 8:
num2 = "OITO";
case 9:
num2 = "NOVE";
}
printf("Quanto e %s vezes %s?: ", num1, num2);
i++;
}
system("pause");
return 0;
}
The error occurs in the assignment of the string num1
and num2
with the message
Incompatible types in assignment of 'const char [5]' to '[char [7]'