/*This program will ask a user to enter a song list. By doing this each time that the user enters
a song, he/she will then be asked if they want to enter another song, if yes then they will enter another song.There will be a maximum of 15 songs.
This progarm will help a user keep track of their songs. But then the program will output the amount of songs, and what they are.
input:A song. Then a yes or no, if yes, another song, if no the program will output.
output:The number of songs, and then the songs themselves, each song with it's own individual line.
processing: There will be two functions, one of which will ask the user for the songs and store them, and another for which will be computing
the output.
*/
#include<iostream>
#include<string>
using namespace std;
void input(string[15], int);
void printArray(string[15], int);
int main()
{
string songarray[15];
int arraysize=15;
int j=0;
input(songarray, arraysize);
int x=songarray[j].length();
cout<<"There were "<<x<<" song titles entered.";
printArray(songarray, x);
return 0;
}
/*This function will ask for the users input for a song and store the song in the songarray. He or she
will then be asked whether or not they want to enter another song, if so, then they will enter another song.
input:a song, y/Y or n/N for if they want to continue or not with another song
output:song will be sent to main function
processing: A while loop will be used for the user to enter is Y or N, and a for loop (while loop nested) for the user to enter the
songs
*/
void input(string titles[15], int rows)
{
char answer='y';
for(int i=0;i<rows && (answer=='Y' || answer=='y');i++)
{
cout<<"Enter the name of a song. ";
cin>>titles[i];
cout<<"Do you want to continue (y/n)? ";
cin>>answer;
}
}
/*The purpose of this function is to print the array from the main function.
input:accepts the array from the main function
output: prints the array
processing:nested loops will pring this array.
*/
void printArray(string playlist[15], int quantity)
{
for(int j=0; j<quantity; j++)
{
cout<<playlist[j];
}
}
因此,預期的輸出是清楚的,程序要求輸入歌曲,然後要求用戶輸入y或n,如果他們想要輸入另一首歌曲,請輸入yes或no。如果是,那麼程序再次提問。但是最大值是15首歌曲,最後如果用戶輸入n或15進入,程序將輸出「有空白歌曲標題輸入」,其中空白是輸入的歌曲數量。我一直在要麼沒有得到輸出,0首歌曲進入和/或沒有靠近輸出我想要的,什麼是我的問題?/爲什麼我的預期輸出不會發生?
這看起來像是家庭作業或測試問題。 – 2011-04-19 03:38:30
等一下,你每次都得到不同的結果?你說'和/或',所以我不太理解你的問題。你能否澄清一點? – Blender 2011-04-19 03:38:53
您可能會發現以下閱讀有幫助:http://www.cprogramming.com/tutorial/references.html – Anton 2011-04-19 04:00:40