Problem with my function [can´t find the solution]

Hello Iam writing a program for replace words in a sentence.
Nothing special, because Iam a newbie ^.^
For example:
"Whats your name?"
Replacefunction();
"Whats your age?".

I guess I´ve done everything well! I researched the internet but I can´t find my mistake? Why there is always an Error?

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

//main.cpp
#include <iostream>
#include <string>
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "textone.h"
using namespace std;

int main ()
{
  TEXT_ONE();
  system("pause");
  getchar();
  return 0;
}
//-----------------------------------------------------
//TEXTONE.CPP

#include "textone.h"
#include <iostream>
#include <string>
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>


void TEXT_ONE()
{
	const int MAXITEMS = 5;
	
    string lastItem;
	string inventory[MAXITEMS] = {"The ", "distortion ", "is ", "totally ", "solid"};
	string replaceItem;
	string addItem;
	
	cerr << "We start with\n" << endl;

	for (int i = 0; i < MAXITEMS; i++)
	{                 
		lastItem = inventory[i];
		cerr << inventory[i] ;                
	}

    cout << endl; 
    cout << endl;
	
//accomplished, imaginative, creative, solid, 
	
srand ( time(NULL) );
int random_number = 0;
random_number = rand() % 4 + 0;

switch (random_number) 
{
  case 1:
       replaceItem = "creative";
       break;
  case 2:
       replaceItem = "imaginative";
       break;
  case 3:
       replaceItem = "accomplished";
       break;
  case 4:
       replaceItem = "solid";
       break;
  default:
    cout << "ERROR" << endl;
  }

random_number = 0;   
    
    inventory[4] = replaceItem;
	cerr << endl << endl;
	

	for (int i = 0; i < MAXITEMS; i++)
	{
		lastItem = inventory[i];
		cerr << inventory[i] << endl << endl;                  
	}
}

//-------------------------------------------------------------------------
//TEXTONE.H

#ifndef TEXTONE_H
#define TEXTONE_H

void TEXT_ONE();

#endif

Thanks for answering me 
and reading my crappy english.


Why there is always an Error?


Showing the errors it gives would make it easier to find the problem.
random_number = rand() % 4 + 0;
random_number gets a value in the range 0-3 but the switch handles numbers 1-4.
Topic archived. No new replies allowed.