I need to write a program that implements a small information system for a gas station. with an array with Type of petrol, price and article number.The program needs to have a menu with Add new type of petrol and Search for an item by article number. The program needs to be with function and pointers
#include <iostream>
#include <string>
#include <sstream>
usingnamespace std;
struct gastation_t
{
int tyofpetrol;
int price;
int articnumber;
} petrol[2];
void printpetrol(gastation_t typofpetrol);
int main(){
int n;
for(n=0;n<2;n++){
cout<<"Enter Type of Petrol 95 or 98: ";
cin>>petrol[n].tyofpetrol;
if(petrol[n].tyofpetrol=95 || petrol[n].tyofpetrol=98){
cout<<"Enter price: ";
cin>>petrol[n].price;
cout<<"Enter articnumber: ";
cin>>petrol[n].articnumber;
}
else{
cout<<"You need to type 95 or 98 petrol";
}
}
cout<<"\n You have entered these petrols: "<<endl;
for(n=0;n<2;n++)
printpetrol(petrol[n]);
return 0;
}
void printpetrol(gastation_t typofpetrol)
{
cout<<"Type of petrol: "<<typofpetrol.tyofpetrol<<endl;
cout<<"The price is: "<<typofpetrol.price<<endl;
cout<<"The article number is: "<<typofpetrol.articnumber<<endl;
}
but something is wrong and i cant continue can oyu help me with the code i got error when i try to check is the number is 95 or 98
i know but when i try i got this error -
main.cpp:19:54: error: expression is not assignable
if(petrol[n].tyofpetrol=95 || petrol[n].tyofpetrol=98){
~~~~~~~~~~~~~~~~~~~~~~~~~~^
1 error generated.
i fix the problem with if statement but i don't know how to make the else statement to be if the number is not ==95 or 98 to ask again and again while the number is 95 or 98
Thanks, but consider that find_by_articnumber() is in fact not really needed, because <algorithm> provides a function named find_if(...). So you could replace find_by_articnumber by: