-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path23-Loops-Exercise.sol
33 lines (26 loc) · 923 Bytes
/
23-Loops-Exercise.sol
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
// SPDX-License-Identifier: MIT
// 1️⃣ Create a loop to calcualte all expenses for the user
// HINT: Create a total expenses variable with uint type
// HINT: Loop over expenses array with for loop
// HINT: add up all expenses cost
// HINT: return total expenses
pragma solidity ^0.8.0;
contract ExpenseTracker {
struct Expense {
address user;
string description;
uint amount;
}
Expense[] public expenses;
constructor() {
expenses.push(Expense(msg.sender, "Groceries", 50));
expenses.push(Expense(msg.sender, "Transportation", 30));
expenses.push(Expense(msg.sender, "Dining out", 25));
}
function addExpense(string memory _description, uint _amount) public {
expenses.push(Expense(msg.sender, _description, _amount));
}
function getTotalExpenses(address _user) public view returns (uint) {
// Your code here
}
}