forked from andreikop/cpp2python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject1.py
More file actions
129 lines (117 loc) · 4 KB
/
Copy pathproject1.py
File metadata and controls
129 lines (117 loc) · 4 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// C++ program to calculate the total earnings on the song based on the payment rates for the streaming service chosen.
#include <iostream>
#include <iomanip>
using namespace std;
// define the constants for the charges in each streaming service
#define TIDAL 0.01250
#define Amazon 0.00402
#define Apple_Music 0.00735
#define Spotify 0.00437
#define YouTube 0.00069
int main() {
int choice;
string artist, song;
int streams;
double earnings;
string streamingService;
// input of streaming service choice
cout<<"Which Streaming Service will you use to upload your song? "<<endl;
cout<<"\t1: TIDAL"<<endl;
cout<<"\t2: Amazon"<<endl;
cout<<"\t3: Apple Music"<<endl;
cout<<"\t4: Spotify"<<endl;
cout<<"\t5: Youtube"<<endl;
cout<<"\nEnter your choice(1-5) : ";
cin>>choice;
// validate the choice
if(choice < 1 || choice > 5)
{
cout<<endl<<"ERROR - NOT A VALID STREAMING SERVICE. PROGRAM WILL TERMINATE"<<endl;
}else
{
// input of artist name, song name
cin.ignore(100,'\n');
cout<<endl<<"What is the artist's name? ";
getline(cin,artist);
artist = artist.substr(0,artist.length()-1); // remove '\n' from end
cout<<endl<<"What is the name of the song? ";
getline(cin,song);
song = song.substr(0,song.length()-1); //remove '\n' from end
// based on the streaming choice input the number of streams and calculate the total earnings if number of streams is positive
// if number of streams is negative then print error and terminate
if(choice == 1)
{
streamingService = "TIDAL";
cout<<endl<<"How many streams does "<<song<<" have on TIDAL ? ";
cin>>streams;
if(streams < 0)
{
cout<<endl<<"ERROR - NUMBER OF STREAMS CANNOT BE NEGATIVE. PROGRAM WILL TERMINATE"<<endl;
return 1;
}else
{
earnings = streams*TIDAL;
}
}else if(choice == 2)
{
streamingService = "Amazon";
cout<<endl<<"How many streams does "<<song<<" have on Amazon ? ";
cin>>streams;
if(streams < 0)
{
cout<<endl<<"ERROR - NUMBER OF STREAMS CANNOT BE NEGATIVE. PROGRAM WILL TERMINATE"<<endl;
return 1;
}else
{
earnings = streams*Amazon;
}
}else if(choice == 3)
{
streamingService = "Apple Music";
cout<<endl<<"How many streams does "<<song<<" have on Apple Music ? ";
cin>>streams;
if(streams < 0)
{
cout<<endl<<"ERROR - NUMBER OF STREAMS CANNOT BE NEGATIVE. PROGRAM WILL TERMINATE"<<endl;
return 1;
}else
{
earnings = streams*Apple_Music;
}
}else if(choice == 4)
{
streamingService = "Spotify";
cout<<endl<<"How many streams does "<<song<<" have on Spotify ? ";
cin>>streams;
if(streams < 0)
{
cout<<endl<<"ERROR - NUMBER OF STREAMS CANNOT BE NEGATIVE. PROGRAM WILL TERMINATE"<<endl;
return 1;
}else
{
earnings = streams*Spotify;
}
}else
{
streamingService = "YouTube";
cout<<endl<<"How many streams does "<<song<<" have on YouTube ? ";
cin>>streams;
if(streams < 0)
{
cout<<endl<<"ERROR - NUMBER OF STREAMS CANNOT BE NEGATIVE. PROGRAM WILL TERMINATE"<<endl;
return 1;
}else
{
earnings = streams*YouTube;
}
}
// if all valid values print the result
cout<<endl<<"Song Name : "<<song<<endl;
cout<<"Artist Name : "<<artist<<endl;
cout<<"Streaming Service : "<<streamingService<<endl;
cout<<"Streams : "<<streams<<endl;
cout<<fixed<<setprecision(2)<<"Earnings : $"<<earnings<<endl;
}
return 0;
}
//end of program