First Time Using C++ ( High School Student)

Pages: 12
Hello, I am currently enrolled in a college course at the community college I attend to, which I'm a Middle College Student currently enrolled in the 10th grade, and I'm currently Having a hard time with my C++ assignment. My output isn't the same as my college instructor and in all honestly I'm kinda lost however i manage to look at his example but I am still having a hard actually writing the code.

Here is my code
Here is my Input (song.dat.txt)
1
2
3
4
5
6
7
8
9
10
11
12
 
310
482
601
259
983
273
567
-12
535
45
300


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
// This data will execute the determine factor of the the data file.  
#include <iostream>                
#include <fstream>    
#include <iomanip>

using namespace std;

int main()
{
	int songMinutes = 0;
	int songSeconds = 0;
	int timeSeconds = 0;
	int totalMinutes = 0;
	int totalSeconds = 0;
	int minutesLeft = 0;
	int secondsLeft = 0;
	int totalTime = 0;
	int usedTime = 0;
	int current = 0;
	int currentMinutes = 0;
	int currentSeconds = 0;
	int usedMinutes;
	int usedSeconds;
	int seconds = 0;
	int newtotalTime = 0;
	int songNumber;
	bool ok = true;

	ifstream inData;
	inData.open("C:\\CSP31A\\songs.dat.txt");
	if (!inData)
	{
		cout << "Can't open the input  file. Cancelling." << endl;
		cin.get();
		return 1;
	}

	songNumber = 1;    //First record
	//Create columns  and heading

	cout << setw(8) << "Song" << setw(28)
		<< "Song Time" << setw(28)
		<< "Total Time" << setw(25)
		<< "Number" << setw(20)
		<< "Minutes" << setw(10)
		<< "Seconds" << setw(18)
		<< "Minutes" << setw(10)
		<< "Seconds" << setw(22)
		<< "-------" << setw(20) << "-------" << setw(10)
		<< "-------" << setw(18) << "-------" << setw(10)
		<< "-------" << endl;
	/*
	cout << fixed << showpoint << setprecision(2) << setw(7)
	<< songNumber << setw(18)
	<< songMinutes << setw(10)
	<< timeSeconds << setw(18)
	<< totalMinutes << setw(10)
	<< totalSeconds << setw(15)
	<< endl;
	*/
	inData >> totalTime;

	//    songNumber = 1;    
	songNumber = 1;
	while (songNumber <= 7)  //Loop until current complete    
	{
		inData >> current;

		//        if (currentSeconds > 59)
		if (current > 59)
		{
			currentMinutes = (current / 60);
			currentSeconds = (current % 60);
		}

		timeSeconds = currentSeconds;
		songMinutes = currentMinutes;
		seconds = (songMinutes * 60);
		usedMinutes = 0;
		usedSeconds = 0;
		/*
		if (currentSeconds > 59)
		{
		currentMinutes = (current / 60);
		currentSeconds = (current % 60);
		}
		*/
		totalMinutes = (usedMinutes + currentMinutes);
		totalSeconds = (usedSeconds + currentSeconds);

		cout << fixed << showpoint << setprecision(2) << setw(7)
			<< songNumber << setw(18)
			<< songMinutes << setw(10)
			<< timeSeconds << setw(18)
			<< totalMinutes << setw(10)
			<< totalSeconds << setw(15) << endl;

		usedTime = (totalMinutes * 60 + totalSeconds);
		minutesLeft = (totalTime - usedTime) / 60;
		//    secondsLeft = (totalTime - minutesLeft) % 60;
		secondsLeft = (totalTime - usedTime) % 60;

		songNumber++;
	}
	//Calculates the time on the cd, time used, 
	//and the time left  on the cd

	totalTime = (80 * 60);
	//Output the minutes  and seconds left on the CD
	cout << "There are " << minutesLeft << " minutes and "
		<< secondsLeft
		<< " seconds left of space on the 80 minute CD." << endl;

	inData.close();
	cin.get();
	cin.get();
	return 0;
}
 
Last edited on
Can you show your output and his output? What specifically are you having trouble with?
This is MY
 OF MY CODE  but my College instructor has something different.  
   Song                   Song Time                  Total Time
   Number             Minutes   Seconds           Minutes   Seconds
  -------             -------   -------           -------   -------
      1                 8         2                 8         2
      2                10         1                10         1
      3                 4        19                 4        19
      4                16        23                16        23
      5                 4        33                 4        33
      6                 9        27                 9        27
      7                 9        27                 9        27
     There are -4 minutes and -17 seconds left of space on the 80 minute CD.
Last edited on
 FROM PROFESSOR 
Song Song Time Total Time
Number Minutes Seconds Minutes Seconds
1 5 10 5 10
2 7 42 12 52
5 4 19 17 11
3 4 33 21 44
4 9 27 31 11
6 8 55 40 6
7 5 0 45 6
There are 34 minutes and 54 seconds of space left on the 80 minute CD. 

Last edited on
What does your college professor have as output?

Also, for code, put [code] before your code and [/code] after it, an for output (like you just posted) put [output] before the output and [/output] after your output. You can (and should) edit your existing posts.
Last edited on
Thank You for informing me
I see you edited your posts, but I don't see any change?
Made the adjustments, took me awhile to figure it out
Lines 70-74: you don't reset current so the condition is true too many times.
First of all you are getting the wrong minutes and seconds and secondly total you should be adding the previous values each time and not display the same thing each time and when seconds > 60 you must subtract 60 from seconds and add 1 to minutes.
Just put something like this for line 88 and 89

1
2
3
4
5
6
7
totalSeconds += currentSeconds;
if( totalSeconds > 60 )
{
    totalSeconds -= 60;
    ++totalMinutes;
}
totalMinutes += currentMinutes;


*edit

Are you sure this is correct?

 
310
482
601
259
983
273
567
-12
535
45
300
How do you have -12 seconds?

Anyways this would be equiv to
 
5 min 10 second
8 minute 2 second
10 minute 1 second
4 minute 19 second
16 minute 23 second
4 minute 33 second
9 minute 27 second
-12 second
8 minute 55 second
45 second
5 minute


These look close to what your teacher has but not the same
Last edited on
giblit yes it does
L B how would I do that? Would i Have to change current to something else?
I'm going over the power-point and I'm still confuse.
This is what you currently have:
70
71
72
73
74
		if (current > 59)
		{
			currentMinutes = (current / 60);
			currentSeconds = (current % 60);
		}
Have you considered this instead?
70
71
72
73
74
75
		if (current > 59)
		{
			currentMinutes = (current / 60);
			currentSeconds = (current % 60);
			current = 0;
		}
Last edited on
Still The same. If only I the required textbook maybe that could help, but since I'm a middle college student I'm not allow to bring the text book home

    Song                   Song Time                  Total Time
   Number             Minutes   Seconds           Minutes   Seconds
  -------             -------   -------           -------   -------
      1                 8         2                 8         2
      2                10         1                18         3
      3                 4        19                22        22
      4                16        23                38        45
      5                 4        33                43        18
      6                 9        27                52        45
      7                 9        27                62        12
     There are -57 minutes and -2 seconds left of space on the 80 minute CD.
Last edited on
Any Body want to help a high school student who is enrolled in a college course??
closed account (o3hC5Di1)
Hi there,

Unless I'm mistaken, the file contains the length of a bunch of songs and you need to show the length graphically. Now:

61
62
63
64
65
inData >> totalTime;

	//    songNumber = 1;    
	songNumber = 1;
	while (songNumber <= 7)


You read in the first number before your while loop, so the first song's length is now in totalTime, which you don't use afterwars except on line 108: totalTime = (80 * 60); where you just assign it a new value. Also, you while-loop will only allow for 7 songs to be read in, yet you have 12 lines in your input file.

A better way to read in all the data would probably be:

1
2
3
4
5
6
7
8
9
int tmp;
while (inData >> tmp)
{
    if (tmp > 0) //check for negative input
    {
        minutes = tmp / 60;
        seconds = tmp % 60;
    }
}


You will need to adapt this to your program of course.
Please do let us know if you require any further assistance.

All the best,
NwN

I would like more help please. I had ask my classmates but none of them wanted to help. One even said i didn't belong in the course. The instructor left to a meeting so i wasn't able to ask questions.
Thanks for all the help. I believe I got it. My output is not identical to my college professor but as for a 10th grader in a college course I think i got it. :)
Why do you keep parroting that you're a tenth grader enrolled in a college course? o_O
Pages: 12