Skip to content

Commit

Permalink
Merge pull request #21 from git-user-cpp/development
Browse files Browse the repository at this point in the history
Bugs fixed + design improved
- improved design in all menus
- fixed bug with 'total_sum' variable in file main.rs
- added message 'the program is stopped' in main.rs
  • Loading branch information
git-user-cpp authored Feb 15, 2023
2 parents 4d584ca + 46abd13 commit 7e816a8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

use colored::Colorize;
mod menu_main;
mod menu_first;
mod menu_second;
Expand All @@ -31,7 +32,7 @@ pub struct Product {

fn main() {

//hashmap for holding products data
//vector for holding products data
let mut products_list: Vec<Product> = Vec::new();

//loop for main menu
Expand All @@ -58,12 +59,16 @@ fn main() {
menu_first::show_first_option();
menu_first::run_first_option(&mut products_list);
}else if choise == 2 {
//variable for total sum
let mut total_sum: f64 = 0.0;

//running the second option
menu_second::show_second_option();
menu_second::run_second_option(&products_list);
menu_second::run_second_option(&products_list, &mut total_sum);
}else if choise == 3 {
//running the third option
menu_third::show_third_option();
}
}
println!(" {}\n{} {} {}\n {}", "------------------------".red(), "|".red(), "The program is stopped".green(), "|".red(), "------------------------".red());
}
2 changes: 1 addition & 1 deletion src/menu_first.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
use crate::Product;
use colored::*;
use colored::Colorize;

//function for showing the first menu option
pub fn show_first_option() {
Expand Down
6 changes: 3 additions & 3 deletions src/menu_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

use colored::*;
use colored::Colorize;

//main menu function
pub fn show_menu() {
println!(" {}\n{} {} {}\n {}\n{} Choose an option: {}\n{} {} {}\n{} {} {}\n{} {} {}\n{} {} {}\n {}\n",
"-----------------------".blue(), "|".blue(),"Finance manager".yellow(), "|".blue(), "-----------------------".blue(), "|".blue(), "|".blue(), "|".blue(), "[1] Insert products".green(), "|".blue(), "|".blue(), "[2] Show total sum ".green(), "|".blue(), "|".blue(), " [3] Show percentage ".green(), "|".blue(), "|".blue(), "[0] Exit".red(), "|".blue(), "-----------------------".blue());
println!(" {}\n{} {} {}\n {}\n{} Choose an option: {}\n{} {} {}\n{} {} {}\n{} {} {}\n{} {} {}\n {}\n{}",
"-----------------------".blue(), "|".blue(),"Finance manager".yellow(), "|".blue(), "-----------------------".blue(), "|".blue(), "|".blue(), "|".blue(), "[1] Insert products".green(), "|".blue(), "|".blue(), "[2] Show total sum ".green(), "|".blue(), "|".blue(), " [3] Show percentage ".green(), "|".blue(), "|".blue(), "[0] Exit".red(), "|".blue(), "-----------------------".blue(), "> Your choise:".red());
}
6 changes: 3 additions & 3 deletions src/menu_second.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ SOFTWARE.
*/

use crate::Product;
use colored::*;
use colored::Colorize;

//function for showing the second menu option
pub fn show_second_option() {
println!(" {}\n{} {} {}\n {}", "-----------------------".blue(), "|".blue(), " Show total sum ".green(), "|".blue(), "-----------------------".blue());
}

//function for running the second menu option
pub fn run_second_option(products: &Vec<Product>) {
pub fn run_second_option(products: &Vec<Product>, sum: &mut f64) {
crate::options::show_list(products);
crate::options::count_total_sum(products);
crate::options::count_total_sum(products, sum);
}
2 changes: 1 addition & 1 deletion src/menu_third.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

use colored::*;
use colored::Colorize;

//function for showing the third menu option
pub fn show_third_option() {
Expand Down
11 changes: 4 additions & 7 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SOFTWARE.
*/

use std::io;
use colored::*;
use colored::Colorize;
use crate::Product;

//function for choosing an option
Expand All @@ -45,18 +45,15 @@ pub fn read_product(tmp: &mut String) -> String {
//function for showing the list of products
pub fn show_list(products: &Vec<Product>) {
for element in products {
println!(" {}\n {} {} {}","-----------------------".red(), element.name, element.price, "\n -----------------------".red());
println!(" {}\n product: {} price: {} {}","-----------------------".red(), element.name, element.price, "\n -----------------------".red());
}
}

//function for counting total sum
pub fn count_total_sum(products: &Vec<Product>) {
//variable for total sum
let mut sum: f64 = 0.0;

pub fn count_total_sum(products: &Vec<Product>, sum: &mut f64) {
//counting total sum
for element in products {
sum += element.price;
*sum += element.price;
}

println!(" {} {}\n {}", "Total sum =".yellow(), sum, "-----------------------".red());
Expand Down

0 comments on commit 7e816a8

Please sign in to comment.