no match for 'operator>>' in 'std::cin >> part' and idk what im doing wrong plz help due tommrrow

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
const int SIZE=5;
int part[SIZE];
float price[SIZE];
int j;
float k;
float totalCost=0;


cout<<setprecision(2) << fixed << showpoint;


for(j=0; j<5; j++)
{
cout<<"Please enter an item number";
cin >>part;
}
for(k=0; k<5; k++)
{ cout<<"please enter the price. ";
cin>>price
}
totalCost=price[SIZE];
system {"pause"};
return 0;
}
cin>>price
Becomes
cin>>price[k];
and
cin>>part;
Becomes
cin>>part[j];
Because both part and price are ARRAYS. If you don't tell in which item of the array you want to store your cin'ned value, it will fail.
totalCost=price[SIZE];
Complete fail.
1. It's a segfault, it will crash.
2. You should add every value by hand.
system {"pause"};
Completely wrong.
1. it's system ("pause");
2. it's recognized as a virus. Use getch();
'part' is an array of 5 characters.

You are trying to take user input and put it in the array as a whole, which doesn't work. You need to put it in only one element of the array.

Ie: part[0] or part[1], or part[j]


Same problem with 'price'
okay essgeeich how do i do it by hand. and disch how do i do that.
and it fixed part of it. lol:) down to 2 errors
I gave you the corrections...
Think in a restrictive way of doing things...
Stay to those rules...
[code]"And use code tags, LOL"[/code]
Well, try this:
1
2
3
4
5
totalCost = 0;
for(int i = 0; i < SIZE; i++)
{
   totalCost += price[/* SECRET, Discover this by yourself, have fun! */];
}
Last edited on
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
const int SIZE=5;
int part[SIZE];
float price[5];
int j;
float k;
float totalCost=0;


cout<<setprecision(2) << fixed << showpoint;


for(j=0; j<5; j++)
{
cout<<"Please enter an item number";
cin >>part[j];
}
for(k=0; k<5; k++)
{ cout<<"please enter the price. ";
cin>>price[k];
}
totalCost += price[0+1+2+3+4+5];
system ("pause");
return 0;
}


okay now it just says this
invalid types `float[5][float]' for array subscript
Last edited on
I edited my post over, it may help you.
i think i got that part but its still showing that error that i last posted. lol sry i just learned this.. so yea
Well... You are clearly new into C++.
There is the correction line.
1
2
3
4
for(int i = 0; i < SIZE; i++)
{
   totalCost += price[i];
}

and remove this line:
totalCost=price[SIZE];
sry i changed it already forgot to change it on that but its still showing the prblem that i posted
and remove this line:
totalCost=price[SIZE];

Did you remove it?
OMG totalCost += price[0+1+2+3+4+5];
That is not the way to do it!
It will become totalCost += price[15]; which is wrong!
Use the FOR loop i posted above!
k did that it complied and now there is a logic error it just keeps asking me for the part number and not asking me for the price or even outputting the price. which i know how to fix the second part lol
Change from float k; in the beginning to int k;
just took taht out i dont even need it. I'm not even using k anymore.
Topic archived. No new replies allowed.