Question

Can someone please tell me why the calculation for earnings is not coming through at the...

Can someone please tell me why the calculation for earnings is not coming through at the end of the program? Thank you.

//This program should tell us about streaming services

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
   int choice, streams;
   double earnings;
   string song;
   string artist;
   string streamingService;
  
   const int Tidal = 0.01250;
   const int Amazon = 0.00402;
   const int Apple_Music = 0.00735;
   const int Spotify = 0.00437;
   const int Youtube = 0.00069;
      
       cout << "Which Streaming Service will you use to upload your song? \n";
       cout << "\t1: Tidal \n";
       cout << "\t2: Amazon \n";
       cout << "\t3: Apple Music \n";
       cout << "\t4: Spotify \n";
       cout << "\t5: Youtube \n\n";
       cout << "\nEnter your choice 1-5: ";
       cin >> choice;
      
       if (choice < 1 || choice > 5)
       {
           cout << "ERROR - NOT A VALID STREAMING CHOICE. THE PROGRAM WILL TERMINATE." << endl;
       }
       else
       {
      
           cin.ignore(100,'\n');
           cout << "\nWhat is the name of the Artist? ";
           getline(cin, artist);
          
           cout << "\nWhat is the name of the song? ";
           getline(cin, song);
       }
       if (choice == 1)
       {
           streamingService = "Tidal";
           cout << "\nHow many streams did " << song << " get on Tidal? ";
           cin >> streams;
          
           if (streams < 0)
           {
               cout << "ERROR - NUMBER OF STREAMS CANNOT BE NEGATIVE. PROGRAM WILL TERMINATE.";
               return 1;
           }
           else
           {
               earnings = streams*Tidal;
           }
       }
       else if (choice == 2)
       {
           streamingService = "Amazon";
           cout << "\nHow many streams did " << song << " get on Amazon? ";
           cin >> streams;
          
           if (streams < 0)
           {
               cout << "ERROR - NUMBER OF STREAMS CANNOT BE NEGATIVE. PROGRAM WILL TERMINATE.";
               return 1;
           }
           else
           {
               earnings = streams * Amazon;
           }
       }
       else if (choice == 3)
       {
           streamingService = "Apple_Music";
           cout << endl << "How many streams did " << song << " get on Apple Music? \n";
           cin >> streams;
          
           if (streams < 0)
           {
               cout << "ERROR - NUMBER OF STREAMS CANNOT BE NEGATIVE. PROGRAM WILL TERMINATE.";
               return 1;
           }
           else
           {
               earnings = streams * Apple_Music;
           }
       }
       else if (choice == 4)
       {
           streamingService = "Spotify";
           cout << endl << "How many streams did " << song << " get on Spotify? \n";
           cin >> streams;
          
           if (streams < 0)
           {
               cout << "ERROR - NUMBER OF STREAMS CANNOT BE NEGATIVE. PROGRAM WILL TERMINATE.";
               return 1;
           }
           else
           {
               earnings = streams * Spotify;
           }
       }
       else if (choice == 5)
       {
           streamingService = "Youtube";
           cout << endl << "How many streams did " << song << " get on Youtube? \n";
           cin >> streams;
          
           if (streams < 0)
           {
               cout << "ERROR - NUMBER OF STREAMS CANNOT BE NEGATIVE. PROGRAM WILL TERMINATE.";
               return 1;
           }
           else
           {
               earnings = streams * Youtube;
           }
       }
  
   cout << endl << "Song Name: " << song << endl;  
   cout << "Artist Name: " << artist << endl;
   cout << "Streaming Service: " << streamingService << endl;
   cout << "Streams: " << streams << endl;
   cout << fixed << showpoint << setprecision(2) << "Earnings: $" << earnings << endl;
   return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

When you declared this variable -

const int Tidal = 0.01250;
   const int Amazon = 0.00402;
   const int Apple_Music = 0.00735;
   const int Spotify = 0.00437;
   const int Youtube = 0.00069;

this are not of int type , they are double type . You have declared them as int type that why you were getting 0 in earning because it was taking only integer part as ie 0

correct way -


const double Tidal = 0.01250;
const double Amazon = 0.00402;
const double Apple_Music = 0.00735;
const double Spotify = 0.00437;
const double Youtube = 0.00069;

I have made the following code changes below and also attach output screenshots

Code -

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
int choice, streams;
double earnings;
string song;
string artist;
string streamingService;
//this shouldn't be int , it should be double value
const double Tidal = 0.01250;
const double Amazon = 0.00402;
const double Apple_Music = 0.00735;
const double Spotify = 0.00437;
const double Youtube = 0.00069;
  
cout << "Which Streaming Service will you use to upload your song? \n";
cout << "\t1: Tidal \n";
cout << "\t2: Amazon \n";
cout << "\t3: Apple Music \n";
cout << "\t4: Spotify \n";
cout << "\t5: Youtube \n\n";
cout << "\nEnter your choice 1-5: ";
cin >> choice;
  
if (choice < 1 || choice > 5)
{
cout << "ERROR - NOT A VALID STREAMING CHOICE. THE PROGRAM WILL TERMINATE." << endl;
}
else
{
  
cin.ignore(100,'\n');
cout << "\nWhat is the name of the Artist? ";
getline(cin, artist);
  
cout << "\nWhat is the name of the song? ";
getline(cin, song);
}
if (choice == 1)
{
streamingService = "Tidal";
cout << "\nHow many streams did " << song << " get on Tidal? ";
cin >> streams;
  
if (streams < 0)
{
cout << "ERROR - NUMBER OF STREAMS CANNOT BE NEGATIVE. PROGRAM WILL TERMINATE.";
return 1;
}
else
{
earnings = streams*Tidal;
}
}
else if (choice == 2)
{
streamingService = "Amazon";
cout << "\nHow many streams did " << song << " get on Amazon? ";
cin >> streams;
  
if (streams < 0)
{
cout << "ERROR - NUMBER OF STREAMS CANNOT BE NEGATIVE. PROGRAM WILL TERMINATE.";
return 1;
}
else
{
earnings = streams * Amazon;
}
}
else if (choice == 3)
{
streamingService = "Apple_Music";
cout << endl << "How many streams did " << song << " get on Apple Music? \n";
cin >> streams;
  
if (streams < 0)
{
cout << "ERROR - NUMBER OF STREAMS CANNOT BE NEGATIVE. PROGRAM WILL TERMINATE.";
return 1;
}
else
{
earnings = streams * Apple_Music;
}
}
else if (choice == 4)
{
streamingService = "Spotify";
cout << endl << "How many streams did " << song << " get on Spotify? \n";
cin >> streams;
  
if (streams < 0)
{
cout << "ERROR - NUMBER OF STREAMS CANNOT BE NEGATIVE. PROGRAM WILL TERMINATE.";
return 1;
}
else
{
earnings = streams * Spotify;
}
}
else if (choice == 5)
{
streamingService = "Youtube";
cout << endl << "How many streams did " << song << " get on Youtube? \n";
cin >> streams;
  
if (streams < 0)
{
cout << "ERROR - NUMBER OF STREAMS CANNOT BE NEGATIVE. PROGRAM WILL TERMINATE.";
return 1;
}
else
{
earnings = streams * Youtube;
}
}
  
cout << endl << "Song Name: " << song << endl;
cout << "Artist Name: " << artist << endl;
cout << "Streaming Service: " << streamingService << endl;
cout << "Streams: " << streams << endl;
cout << fixed << showpoint << setprecision(2) << "Earnings: $" << earnings << endl;
return 0;
}

Screenshot -

Add a comment
Know the answer?
Add Answer to:
Can someone please tell me why the calculation for earnings is not coming through at the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Fix my code, if I the song or the artist name is not on the vector,...

    Fix my code, if I the song or the artist name is not on the vector, I want to user re-enter the correct song or artist name in the list, so no bug found in the program #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; class musicList{ private: vector<string> songName; vector<string> artistName; public: void addSong(string sName, string aName){ songName.push_back(sName); artistName.push_back(aName); } void deleteSongName(string sName){ vector<string>::iterator result = find(songName.begin(), songName.end(), sName); if (result == songName.end()){ cout << "The...

  • Please can someone check that program and compile them (send the picture of the runing window)...

    Please can someone check that program and compile them (send the picture of the runing window) A-squareprogram #include <iostream> using namespace std; void squareProgram() { int length; int area; int perimeter; cout << "\n\nWhat is the side length of your square: "; cin >> length; area = (length * length); perimeter = (length * 4); cout << "\n\nYou have a square with a perimeter of " << perimeter << " units and an area of " << area << "...

  • c++, I am having trouble getting my program to compile, any help would be appreciated. #include...

    c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...

  • When running the program at the destructor  an exception is being thrown. Can someone help me out?...

    When running the program at the destructor  an exception is being thrown. Can someone help me out? vararray.h: #ifndef VARARRAY_H_ #define VARARRAY_H_ class varArray { public:    varArray(); // void constructor    int arraySize() const { return size; } // returns the size of the array    int check(double number); // returns index of element containg "number" or -1 if none    void addNumber(double); // adds number to the array    void removeNumber(double); // deletes the number from the array   ...

  • I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for.....

    I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for..while..do while,loops,pointer,address,continue,return,break. Create a C++ program which contain a function to ask user to enter user ID and password. The passwordmust contain at least 6 alphanumeric characters, 1 of the symbols !.@,#,$,%,^,&,* and 1 capital letter.The maximum allowable password is 20. Save the information. Test the program by entering the User ID and password. The...

  • 13.21 Lab: Rational class This question has been asked here before, but every answer I have...

    13.21 Lab: Rational class This question has been asked here before, but every answer I have tested did not work, and I don't understand why, so I'm not able to understand how to do it correctly. I need to build the Rational.cpp file that will work with the main.cpp and Rational.h files as they are written. Rational Numbers It may come as a bit of a surprise when the C++ floating-point types (float, double), fail to capture a particular value...

  • Plz give me correct code and screen shots for this question by using SASM !!!!!!!! Implement...

    Plz give me correct code and screen shots for this question by using SASM !!!!!!!! Implement the following working C++ program in assembler. Submit assembler code and screen shot. #include <iostream> #include <iomanip> using namespace std; // This menu-driven Health Club membership program carries out the // appropriate actions based on the menu choice entered. A do-while loop // allows the program to repeat until the user selects menu choice 4. int main() { // Constants for membership rates const...

  • Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string>...

    Can you tell me what is wrong and fix this code. Thanks #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; //function void displaymenu1(); int main ( int argc, char** argv ) { string filename; string character; string enter; int menu1=4; char repeat; // = 'Y' / 'N'; string fname; string fName; string lname; string Lname; string number; string Number; string ch; string Displayall; string line; string search; string found;    string document[1000][6];    ifstream infile; char s[1000];...

  • I'm kind of new to programming, and I am having trouble figuring out why my program...

    I'm kind of new to programming, and I am having trouble figuring out why my program isn't running. Below is the code that I wrote for practice. I will comment where it says the error is. So the error that I'm getting is "error: no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' ". I'm not sure why I'm getting this because I added the library <iostream> at the top. Thank you. Code: #include <iostream> using namespace std; class...

  • Can you fix this program and run an output for me. I'm using C++ #include using...

    Can you fix this program and run an output for me. I'm using C++ #include using namespace std; //function to calculate number of unique digit in a number and retun it int countUniqueDigit(int input) {    int uniqueDigitCount = 0;    int storeDigit = 0;    int digit = 0;    while (input > 0) {        digit = 1 << (input % 10);        if (!(storeDigit & digit)) {            storeDigit |= digit;       ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT