multiple errors of invalid conversion and previous declaration

In this there are conflicting declaration(declared more than once), cannot convert(int* to int)(double* to double)(not sure), and initializing argument(really no idea). the function names cannot be changed any help would be welcome.

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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <fstream>
using namespace std;

void showMenu();
bool testSoldNumbers(int, int, const int);
double showValue(double);
void showValues(int, const int);
double getTotal(double, const int);
int getLowest(int, const int);
double getLowest(double, const int);
int getLowestIndex(double, const int);
double getHighest(double, const int, int);

int main()
{
  const int SIZE=10;
  double bookCosts[SIZE], bookSales[SIZE], totalSales[SIZE];
  int soldNumbers[SIZE], soldNumbers2[SIZE]={4, 6, 8, 10, 3, 5, 7\
, 9, 11, 12};
  bool isEqual=true;
  ifstream inFile;
  ofstream outFile;
  int count=0, choice, lowest, lowestIndex, highIndex=0;
  double totalSales, sum, lowest, highest;

 inFile.open("hw12-1_input.txt");
  outFile.open("hw12-1_output.txt");
    if(!inFile)
      {
        cout<<"Could not open input file.\n";
        return 1;
      }

  while(count<SIZE && inFile>>bookCosts[count])
    {
      count++;
    }

do
  {
    showMenu();
    cin>>choice;
    if(choice<1 ||choice>9)
      {
        cout<<"Invalid entry, please choose 1-9;\n";
        cin>>choice;
      }

    switch(choice)
      {
      case 1:
        while(inFile)
          for(int i=0;i<SIZE;i++)
            cout<<bookCosts[i]<<", ";
        break;


      case 2:
        double bookSales[SIZE];
        double tax;
        cout<<"Please enter the decimal value of tax:\n";
        cin>>tax;
        for(int i=0;i<SIZE;i++)
          {
            bookSales[i]=bookCosts[i]+(bookCosts[i]*tax);
            outFile<<bookSales[i];
          }
        break;

      case 3:
        for(int i=0;i<SIZE;i++)
          cout<<"The sale price for book #"<<(i+1)<<" is "<<bookS\
ale[i]<<endl;
        break;

      case 4:
        for(int i=0;i<SIZE;i++)
          {
        cout<<"Enter the number of books sold for book #"<<(i+1)<\
<endl;
        cin>>soldNumbers[i];
          }
        break;

      case 5:
        testSoldNumbers(soldNumbers, soldNumbers2, SIZE);
        if(isEqual==true)
          cout<<"These two sales are the same"<<endl;
        else
          cout<<"These two sales were not the same"<<endl;
        break;

      case 6:
        for(int i=0;i<SIZE;i++)
          {
            totalSales[i]=bookSales[i]*soldNumbers[i];
            showValue(totalSales);
          }

        showValues(soldNumbers, SIZE);
        break;

      case 7:
        getTotal(totalSales, SIZE);
        cout<<"The amount of totalSales is $"<<totalSales<<endl;

      case 7:
        getTotal(totalSales, SIZE);
        cout<<"The amount of totalSales is $"<<totalSales<<endl;

        getLowest(soldNumbers, SIZE);
        cout<<"The lowest number of books sold is "<<lowest<<endl\
;

        getLowest(bookCosts, SIZE);
        cout<<"The lowest book cost is $"<<lowest<<endl;

        getLowestIndex(bookCosts, SIZE);
        cout<<"The lowest cost belongs to book #"<<lowestIndex<<e\
ndl;
        break;

      case 8:
        getHighest(bookCosts, SIZE, &highIndex);

      default:
        break;

      }
  }while(choice!=9);
 return 0;
}

void showMenu()
{
  cout<<"Integer Array Menu\n";
  cout<<"\t"<<"1. Display all book costs\n";
  cout<<"\t"<<"2. Compute sale prices\n";
  cout<<"\t"<<"3. Display all sale prices\n";
  cout<<"\t"<<"4. Store number of books sold\n";
  cout<<"\t"<<"5. Compare two arrays\n";
  cout<<"\t"<<"6. Calculate total sales and display\n";
  cout<<"\t"<<"7. Find total and min\n";
  cout<<"\t"<<"8. Find max\n";
  cout<<"\t"<<"9. Quit\n";
  cout<<"Enter your choice\n";
}

bool testSoldNumbers(int soldNumbers[], int soldNubers2[], const \
int SIZE)
{
  bool isEqual=true;
  for(int i=0;i<SIZE;i++)
    {
      if(soldNumbers[i]!=soldNumbers2[i])
        isEqual=false;
      else
        isEqual=true;
    }
  return isEqual;
}

void showValue(double totalSales[])
{
  int i=0;
  cout<<"The total sales price for book #"<<(i+1)<<" is \         
$"<<totalSales[i]<<endl;
  i++;
}

void showValues(int soldNumbers[], const int SIZE)
{
  for(int i=0;i<SIZE;i++)
    cout<<"The number of sold books for book #"<<(i+1)<<" is $"<<\
soldNumbers[i]<<endl;

}

double getTotal(double totalSales[], const int SIZE)
{
  double sum=0.0;
  for(int i=0;i<SIZE;i++)
    {
      sum+=totalSales[i];
    }
  return sum;
}

int getLowest(int soldNumbers[], const int SIZE)
{
  int lowest=soldNumbers[0];
  for(int i=1;i<SIZE;i++)
    {
      if(soldNumbers[i]<lowest)
        lowest=soldNumbers[i];
    }
  return lowest;
}

double getLowest(double bookCosts[], const int SIZE)
{
  int lowest=bookCosts[0];
  for(int i=1;i<SIZE;i++)
    {
      if(bookCosts[i]<lowest)
        lowest=bookCosts[i];
    }
  return lowest;
}

int getLowestIndex(double bookCosts[], const int SIZE)
{
  int lowestIndex=0;
  for(int i=1;i<SIZE;i++)
    {
      if(bookCosts[i]<bookCosts[lowestIndex])
        lowestIndex=i;
    }
  return lowestIndex;
}

double getHighest(double bookCosts[], const int SIZE, int &highIn\
dex)
{
  double highest=bookCosts[0];
  for(int i=1;i<SIZE;i++)
    {
      if(bookCosts[i]>highest)
        {
          highest=bookCosts[i];
          highIndex=i;
        }
    }
  return highest;
}



yes, this is school work, but I'm not asking for someone to fix it. I am, however, asking for understanding so that i can fix it. The error messages are as follows:

hw12-1_book_store.cpp: In function ‘int main()’:
hw12-1_book_store.cpp:28:10: error: conflicting declaration ‘double totalSales’
double totalSales, sum, lowest, highest;
^
hw12-1_book_store.cpp:22:44: error: ‘totalSales’ has a previous declaration as ‘double totalSales [10]’
double bookCosts[SIZE], bookSales[SIZE], totalSales[SIZE];
^
hw12-1_book_store.cpp:28:27: error: conflicting declaration ‘double lowest’
double totalSales, sum, lowest, highest;
^
hw12-1_book_store.cpp:27:24: error: ‘lowest’ has a previous declaration as ‘int lowest’
int count=0, choice, lowest, lowestIndex, highIndex=0;
^
hw12-1_book_store.cpp:75:54: error: ‘bookSale’ was not declared in this scope
cout<<"The sale price for book #"<<(i+1)<<" is "<<bookSale[i]<<endl;
^
hw12-1_book_store.cpp:87:49: error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive]
testSoldNumbers(soldNumbers, soldNumbers2, SIZE);

hw12-1_book_store.cpp:10:6: error: initializing argument 1 of ‘bool testSoldNumbers(int, int, int)’ [-fpermissive]
bool testSoldNumbers(int, int, const int);
^
hw12-1_book_store.cpp:87:49: error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive]
testSoldNumbers(soldNumbers, soldNumbers2, SIZE);
^
hw12-1_book_store.cpp:10:6: error: initializing argument 2 of ‘bool testSoldNumbers(int, int, int)’ [-fpermissive]
bool testSoldNumbers(int, int, const int);
^
hw12-1_book_store.cpp:98:26: error: cannot convert ‘double*’ to ‘double’ for argument ‘1’ to ‘double showValue(double)’
showValue(totalSales);
^
hw12-1_book_store.cpp:101:30: error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive]
showValues(soldNumbers, SIZE);
^
hw12-1_book_store.cpp:12:6: error: initializing argument 1 of ‘void showValues(int, int)’ [-fpermissive]
void showValues(int, const int);
^
hw12-1_book_store.cpp:105:27: error: cannot convert ‘double*’ to ‘double’ for argument ‘1’ to ‘double getTotal(double, int)’
getTotal(totalSales, SIZE);
^
hw12-1_book_store.cpp:108:29: error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive]
getLowest(soldNumbers, SIZE);

hw12-1_book_store.cpp:14:5: error: initializing argument 1 of ‘int getLowest(int, int)’ [-fpermissive]
int getLowest(int, const int);
^
hw12-1_book_store.cpp:111:27: error: invalid conversion from ‘double*’ to ‘int’ [-fpermissive]
getLowest(bookCosts, SIZE);
^
hw12-1_book_store.cpp:14:5: error: initializing argument 1 of ‘int getLowest(int, int)’ [-fpermissive]
int getLowest(int, const int);
^
hw12-1_book_store.cpp:114:32: error: cannot convert ‘double*’ to ‘double’ for argument ‘1’ to ‘int getLowestIndex(double, int)’
getLowestIndex(bookCosts, SIZE);
^
hw12-1_book_store.cpp:119:40: error: cannot convert ‘double*’ to ‘double’ for argument ‘1’ to ‘double getHighest(double, int, int)’
getHighest(bookCosts, SIZE, &highIndex);
^
hw12-1_book_store.cpp: In function ‘bool testSoldNumbers(int*, int*, int)’:
hw12-1_book_store.cpp:149:26: error: ‘soldNumbers2’ was not declared in this scope
if(soldNumbers[i]!=soldNumbers2[i])
Hello vtravis,

I have not tracked down all the errors you have listed, but these jumped out quickly.

Line 22 you define "totalSales[SIZE]" and on line 29 you define "totalSales". You may be think that one is an array and one is a single variable, but this is not enough to make them different, so the compiler sees line 29 as a redefinition of "totalAsles". To make them different you could do "aTotalSales" and "totalSales" with the "a" to give the idea that it is an array. Now they are different.

Also on line 22 you define "bookSales[SIZE]". This has the scope from the opening { of main to the closing } of main. So on line 64 when you define "bookSales[SIZE]" it is a redefinition of line 22 because it is in the local scope of "main" and the switch is contained in the scope of "main". The bigger question is why you feel the need to define "bookSales" in the case statement?

Another problem is, using "lowest" as an example, line 28 defines "lowest" as an int and then on line 29 you try to redefine "lowest" as a double. Variable type alone does not make a difference. They are still the same name.

The errors on what I believe to be lines 101 and 102, what is referred to as lines 98 and 101 in the error messages, is because of trying to redefine your arrays as a single variable with the same name.

A lot of the time fixing one or more of the first errors listed will clear up many of the other errors. So I would work on not using the same name for an array and the again for a single variable.and that should eliminate most of your errors.

Hope that helps,

Andy
> yes, this is school work, but I'm not asking for someone to fix it.
I can tell you that you should have pressed 'compile' long before you actually did.

Nobody (even pro's with decades of experience) writes 200+ lines of code without pressing compile even once.

Write 10 lines, press compile, fix a very small number of errors (if any).
When it compiles, TEST it to make sure it does what you expect.
Rinse and repeat.

One new error in the most recent edit is easy to fix, because the change is so fresh in your mind.

Hours of editing and then pages of errors just leaves you confused.
The biggest problem with your code is that your function prototypes do not match your function definitions. Function prototypes must match the function definitions EXACTLY in both argument types and return type. In your function prototypes, you're telling the compiler to expect a simple variable, while your function definitions are expecting arrays.
10
11
12
13
14
15
16
17
bool testSoldNumbers(int[], int[], const int);
void showValue(double[]);
void showValues(int[], const int);
double getTotal(double[], const int);
int getLowest(int[], const int);
double getLowest(double[], const int);
int getLowestIndex(double[], const int);
double getHighest(double[], const int, int &);


Lines 107,111: Duplicate case values.

Line 22, 29: You're declaring totalSales twice.

Line 28, 29: Duplicate definition of lowest (with different types).

Line 112: Did you mean to cout the simple variable, or the array. You can't cout an array.

Line 115,119: Which lowest are you trying to cout here? The int or the double?

Line 126: & not needed.

Line 151: soldNumbers2 is misspelled.

Line 155-161: Your for loop logic is flawed. You overlay isEqual each time through the loop.

Line 203: Type mismatch. You're assigning a double to an int. You're going to lose significance.

Multiple places: The compiler does not like how you've broken up your lines. Break lines at whitespace.









Topic archived. No new replies allowed.