- #1
WarGhSt
- 15
- 0
Working on an I/O assignment and I'm running into some logic errors. I was wondering if I could get a quick break down (not necessarily code, but the pseudo code behind some of these points I'm supposed to be working on. That way I don't get spoiled with the answers, but have enough to go on compared to what I'm doing right now which is banging my head against a very solid wall.
Running this with multiple functions as I was advised to try in my last program (Didn't end up using it there, but I'm running with it now)
View attachment 5469
services.txt
code for my program
I've modified my services.txt to carry the serviceValue of 1 for everything except swimming which has a value of 3 so that the display when the membership is Family it will return the kids swimming option but it's a really awful way of doing things. And won't work for the final program.
After that task, I'm having a hard time linking the membership value (individual, couples, family) to the discounts. Is it possible to get that done with the help of one of the three functions I have now?
Finally, and I'm sure this task will be easy once I've solved the problem above, the srand to apply a random discount to the gym member.
Running this with multiple functions as I was advised to try in my last program (Didn't end up using it there, but I'm running with it now)
View attachment 5469
services.txt
Code:
Cafe:Smoothies
SPA:Hair and Skin
Training:90 day challenge
Aquatics:Kids free training session
code for my program
Code:
#include <iostream>
#include <fstream>
#include <time.h>
using namespace std;
int getMenuChoice();
void displayServices(int x);
int discountValue(int y);
//main function
int main(){
int whatTheyAre;
whatTheyAre = getMenuChoice();
while(whatTheyAre != 4){
switch(whatTheyAre){
case 1:
cout << "You are paying for the individuals membership, which is $500." << endl;
cout << "And you are entitled to the following services: " << endl;
displayServices(1);
break;
case 2:
cout << "You are paying for the couples membership, which is $800." << endl;
cout << "And you are entitled to the following services: " << endl;
displayServices(2);
break;
case 3:
cout << "You are paying for the family membership, which is $1200." << endl;
cout << "And you are entitled to the following services: " << endl;
displayServices(3);
break;
}
//another chance to choose a new choice
whatTheyAre = getMenuChoice();
}
}
//getWhatTheyWant function
int getMenuChoice(){
int menuChoice;
cout << "Enter 1 - If you are paying for an individual membership" << endl;
cout << "Enter 2 - If you are paying for a couples membership" << endl;
cout << "Enter 3 - If you are paying for a family membership" << endl;
cout << "Enter 4 - To quit program" << endl;
cin >> menuChoice;
return menuChoice;
}
//display Services function
void displayServices(int x){
ifstream objectFile("services.txt");
string name;
int serviceValue;
if(x == 1){
while(objectFile >> name >> serviceValue){
if(serviceValue == 1){
cout << name << endl;
}
}
}
if(x == 2){
while(objectFile >> name >> serviceValue){
if(serviceValue == 1){
cout << name << endl;
}
}
}
if(x == 3){
while(objectFile >> name >> serviceValue){
if(serviceValue <= 2){
cout << name << endl;
}
}
}
}
I've modified my services.txt to carry the serviceValue of 1 for everything except swimming which has a value of 3 so that the display when the membership is Family it will return the kids swimming option but it's a really awful way of doing things. And won't work for the final program.
After that task, I'm having a hard time linking the membership value (individual, couples, family) to the discounts. Is it possible to get that done with the help of one of the three functions I have now?
Finally, and I'm sure this task will be easy once I've solved the problem above, the srand to apply a random discount to the gym member.