#include "stdafx.h"
#include<iostream>
using namespace std;
class bank
{
public: char name[20];
public: float balance;
public: void get()
{
cout << "\nEnter name and balance in Account respectively\n";
cin >> name >> balance;
}
public: void display()
{
cout << "Name: " << name << " Balance: " << balance;
}
};
void main()
{
int i = 0;
bank b[10];
bank max;
bank temp;
for (i = 0; i < 10; i++)
{
b[i].get();
}
for (i = 0; i < 10; i++)
{
if (b[i + 1].balance > b[i].balance)
{
max.balance = b[i + 1].balance;
max.name = b[i + 1].name;//Error 1 error C2106: '=' : left operand must be l-value
}
else
{
temp.balance = b[i + 1].balance;
temp.name = b[i + 1].name;//Error 2 error C2106: '=' : left operand must be l-value
b[i + 1].balance = b[i].balance;
b[i + 1].name = b[i].name;//Error 3 error C2106: '=' : left operand must be l-value
b[i].balance = temp.balance;
b[i].name = temp.name;//Error 4 error C2106: '=' : left operand must be l-value
max.balance = b[i + 1].balance;
max.name = b[i + 1].name;//Error 5 error C2106: '=' : left operand must be l-value
}
}
max.display();
}
In this program I've to take input as name and balance of 10 people and display the output as name and balance corresponding to the highest balance. Besides the errors shown in the code itself as comments, I'm also getting another code at same those lines only where I've put a comment regarding the error. That other error is:
IntelliSense: expression must be a modifiable lvalue
I'm using Visual Studio Professional 2013 and the code is in visual C++