My friend needs help with his project I dont know why one line isnt being read

"cin >> views seems to not work"

it simply ignores it

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
130
131
132
  // This program calculates how much a song makes on different streaming services
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()
{

int choice;
int views;
string artist;
string song;
// Choice= streaming selection/ num= the amount of views the song gets.
// This is where the menu is displayed

cout << "Which streaming service will you use to upload your song? " << endl;
cout << " 1: TIDAL " << endl;
cout << " 2: Amazon " << endl;
cout << " 3: Apple Music " << endl;
cout << " 4: Spotify " << endl;
cout << " 5: Youtube " << endl;

cout << " Please enter a number (1-5) to select which service you want to upload to. " << endl;

cin >> choice;

// TIDAl= 0.0125, Amazon= 0.00402, AM(Apple Music)= 0.00737, Spotify= 0.00437, Youtube= 0.00069
double Tidal= 0.0125, Amazon= 0.00402, AM= 0.00737, Spotify= 0.00437, Youtube= 0.00069;

// The lines below are the calcualtions based on the different choices the user imputs.
// Each of the choice options below as the user for the name of the artist, the name of the song, and how many views it has.
if (choice == 1)
{

	
	    cout << " What is the Artist's name? " << endl;
        cin >> artist;
        cout << " What song from the artist do you want to upload? " << endl;
        cin >> song;
    
		cout << " How many views does the song have? " << endl;
		cin >> views;

		cout << "Song Name: " << song << endl;
	    cout << "Artist's Name: " << artist << endl;
	    cout << "Streaming Service: " << "TIDAL" << endl;
	    cout << "Money Made $ " << (Tidal * views) << endl;


}

if (choice == 2)
{
	
     cout << " What is the Artist's name? " << endl;
     cin >> artist;
	 cout << " What song from the artist do you want to upload? " << endl;
	 cin >> song;
	
	 cout << " How many views does the song have? " << endl;
	 cin >> views;
	 
	 cout << "Song Name: " << song << endl;
	 cout << "Artist's Name: " << artist << endl;
	 cout << "Streaming Service: " << "Amazon" << endl;
	 cout << "Money Made $ " << (Amazon * views) << endl;
	
}

if (choice == 3)
{
	
	 cout << " What is the Artist's name? " << endl;
	 cin >> artist;
	 cout << " What song from the artist do you want to upload? " << endl;
	 cin >> song;
	   
	 cout << " How many views does the song have? " << endl;
	 cin >> views;
	 
	 cout << "Song Name: " << song << endl;
	 cout << "Artist's Name: " << artist << endl;
	 cout << "Streaming Service: " << "Apple Music" << endl;
 	cout << "Money Made $ " << (AM * views) << endl;
	
}

if (choice == 4)
{
	
	 cout << " What is the Artist's name? " << endl;
	 cin >> artist;
	 cout << " What song from the artist do you want to upload? " << endl;
	 cin >> song;
	
	 cout << " How many views does the song have? " << endl;
	 cin >> views;
	
	 cout << "Song Name: " << song << endl;
	 cout << "Artist's Name: " << artist << endl;
	 cout << "Streaming Service: " << "Spotify" << endl;
	 cout << "Money Made $ " << (Spotify * views);
	
}

if (choice == 5)
{
	
	cout << " What is the Artist's name? " << endl;
	cin >> artist;
	cout << " What song from the artist do you want to upload? " << endl;
	cin >> song;
	
	cout << " How many views does the song have? " << endl;
	cin >> views;
	
	cout << "Song Name: " << song << endl;
	cout << "Artist's Name: " << artist << endl;
	cout << "Streaming Service: " << "Youtube" << endl;
	cout << "Money Made $ " << (Youtube * views);
}

if (choice >= 6)
{
	
	cout << " Error: Choice entered is not in the range of choices (1-5)" << endl;
}

return 0;
}
Last edited on
What are you inputting into the program.

Do you realize that the extraction operator>> will only accept a single "word"?

It's probably because you are entering more than a single word for artist and/or song, in which case you will need getline() instead of cin
Here's a start to a flood of possible improvements and simplifications. Next step a switch, then on to arrays lists or vectors. Could even have a go-around to try again where wrong choices are made, or just to check another item.


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
// This program calculates how much a song makes on different streaming services
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()
{
    
    int choice{0};
    int views{0};
    string artist;
    string song;
    
    string streaming_service;
    double rate{0};
    // Choice= streaming selection/ num= the amount of views the song gets.
    // This is where the menu is displayed
    
    cout << "Which streaming service will you use to upload your song? " << endl;
    cout << " 1: TIDAL " << endl;
    cout << " 2: Amazon " << endl;
    cout << " 3: Apple Music " << endl;
    cout << " 4: Spotify " << endl;
    cout << " 5: Youtube " << endl;
    
    cout << " Please enter a number (1-5) to select which service you want to upload to. " << endl;
    
    cin >> choice;
    
    double Tidal= 0.0125, Amazon= 0.00402, AM= 0.00737, Spotify= 0.00437, Youtube= 0.00069;
    
    if (choice == 1)
    {
        streaming_service = "TIDAL";
        rate = Tidal;
    }
    
    if (choice == 2)
    {
        streaming_service = "Amazon";
        rate = Amazon;
    }
    
    if (choice == 3)
    {
        streaming_service = "Apple Music";
        rate = AM;
    }
    
    if (choice == 4)
    {
        streaming_service = "Spotify";
        rate = Spotify;
    }
    
    if (choice == 5)
    {
        streaming_service = "Youtube";
        rate = Youtube;
    }
    
    if (choice < 1 or choice >5)
    {
        cout << " Error: Choice entered is not in the range of choices (1-5)\n";
        return -99;
    }
    
    cin.ignore(1000, '\n'); // MOST IMPORTANT
    cout << " What is the Artist's name? ";
    getline (cin, artist);
  
    
    cout << " What song from the artist do you want to upload? ";
    getline (cin, song);
    
    cout << " How many views does the song have? ";
    cin >> views;
    
    cout
    << "\n------------------------------------\n"
    << "        Song Name: " << song << '\n'
    << "    Artist's Name: " << artist << '\n'
    << "     No. of views: " << views << '\n'
    << "            Rate $ " << rate << '\n'
    << "Streaming Service: " << streaming_service << '\n'
    << "      Money Made $ " << rate * views << '\n'
    << "------------------------------------\n";
    
    return 0;
}


Which streaming service will you use to upload your song? 
 1: TIDAL 
 2: Amazon 
 3: Apple Music 
 4: Spotify 
 5: Youtube 
 Please enter a number (1-5) to select which service you want to upload to. 
2
 What is the Artist's name? Alan Artist
 What song from the artist do you want to upload? Alan's greatest hits
 How many views does the song have? 34

------------------------------------
        Song Name: Alan's greatest hits
    Artist's Name: Alan Artist
     No. of views: 34
            Rate $ 0.00402
Streaming Service: Amazon
      Money Made $ 0.13668
------------------------------------
Program ended with exit code: 0
Last edited on
Topic archived. No new replies allowed.