2016-04-12 15 views
1

私は初心者のプログラミングクラスを受講しており、私は割り当てに問題があります。私はデータを保存して並べ替えることができるプログラムを作っています(私はゲームを選択しました)、すべてがうまくいくようです。ゲームを入力して後で入力したゲームを表示する場合を除いて、リストには何も表示されません。私は行方不明のものがありますか?データが表示されないように保存していますか?

#include <cstdlib> 
#include <iostream> 
#include <iomanip> 
#include <fstream> 
#include <string> 
#include <sstream> 
using namespace std; 

struct VidyaGames { 
string Title; 
string Date; 
string Developer; 
}; 

void getGames(VidyaGames array[], int &k); 
void displayGames(VidyaGames array[], int &k); 
void deleteGames(VidyaGames array[], int &k); 
void sortGames(VidyaGames array[], int &k); 



const int MAX = 150; 

string Title; 
string Date; 
string Developer; 

int main() 
{ 
char choice; 
VidyaGames array[MAX]; 
bool kek = true; 
int k = 0; 

do 

{ 

    cout << "Welcome to the 'Super Incredible Amazing Game Storage-o-Tron 5000(and one)." << endl; 
    cout << " " << endl; 
    cout << "Please select which task you would like to perform by typing in the " << endl; 
    cout << "corresponding letter in the bracket: " << endl; 
    cout << " " << endl; 
    cout << "[I]nput a game into the list." << endl; 
    cout << "[D]isplay the games you have stored." << endl; 
    cout << "[S]ort the games you have stored." << endl; 
    cout << "[R]emove a game from the list." << endl; 
    cout << "[Q]uit the program." << endl; 
    cin >> choice; 

    switch (choice) 
    { 
     case 'I': getGames(array, k); break; 
     case 'D': displayGames(array, k); break; 
     case 'S': deleteGames(array, k); break; 
     case 'R': deleteGames(array, k); break; 
     case 'Q': kek = false; break; 
     default : cout << "Hey. Remember when I gave you the specific  options you were allowed to choose?" << endl; 
        cout << "Maybe enter one of those?" << endl; 
        cout << " " << endl; 
     } 
     } 
while (kek); 
cout << "You have killed me." << endl; 

} 
void getGames(VidyaGames array[], int &k) 
{ 
system("cls"); 
VidyaGames tmp; 
char lel[100]; 
cout << "Enter the title of your game: " << endl; 
getline (cin, Title); 
cout << "Enter the date your game was published: (Example: March 15th, 2014)" << endl; 
getline (cin, Date); 
cout << "Enter the developer of your game: " << endl; 
getline (cin, Developer); 

} 

void displayGames(VidyaGames array[], int &k) 
{ 
system ("cls"); 
if (k==0) 
    cout << "There is literally nothing in this list, as you have made the mental choice to not put anything in it yet." << endl; 


else if (k > 0) { 
for (int i=0; i < 0; i++) 
{ 
    cout << "Title: " << array[i].Title << endl; 
    cout << "Release Date: " << array[i].Date << endl; 
    cout << "Developer: " << array[i].Developer << endl; 
    } 
} 
} 


    void deleteGames(VidyaGames array[], int &k) { 


system("cls"); 
char deleteChoice; 
if (k==0) 
    cout << "There is literally nothing in this list, as you have made the mental choice to not put anything in it yet." << endl; 
else { 
    cout << "Please type the name of the game you would like to delete: " << endl; 
    cin >> deleteChoice; 

} 
} 

    void sortGames(VidyaGames array[], int &k) 
    { 

    } 
+2

:これは最終的なコードである

for (int i=0; i < k; i++) 

iはgetGamesを機能させる4行を追加します。配列。 getGames()で行うことは、グローバル文字列への読み込み入力だけです。 – Pemdas

答えて

1

あなたの配列に値を設定するのは忘れてしまいます。

array->Title = Title; 
array->Date = Date; 
array->Developer = Developer; 
k++; 

と関数displayGamesで1行変更します:あなたが実際に移入する必要があり

// test_3.cpp : Defines the entry point for the console application. 
// 

#include "stdafx.h" 


#include <cstdlib> 
#include <iostream> 
#include <iomanip> 
#include <fstream> 
#include <string> 
#include <sstream> 
using namespace std; 

struct VidyaGames { 
    string Title; 
    string Date; 
    string Developer; 
}; 

void getGames(VidyaGames array[], int &k); 
void displayGames(VidyaGames array[], int &k); 
void deleteGames(VidyaGames array[], int &k); 
void sortGames(VidyaGames array[], int &k); 



const int MAX = 150; 

string Title; 
string Date; 
string Developer; 

int main() 
{ 
    char choice; 
    VidyaGames array[MAX]; 
    bool kek = true; 
    int k = 0; 

    do 

    { 

     cout << "Welcome to the 'Super Incredible Amazing Game Storage-o-Tron 5000(and one)." << endl; 
     cout << " " << endl; 
     cout << "Please select which task you would like to perform by typing in the " << endl; 
     cout << "corresponding letter in the bracket: " << endl; 
     cout << " " << endl; 
     cout << "[I]nput a game into the list." << endl; 
     cout << "[D]isplay the games you have stored." << endl; 
     cout << "[S]ort the games you have stored." << endl; 
     cout << "[R]emove a game from the list." << endl; 
     cout << "[Q]uit the program." << endl; 
     cin >> choice; 

     switch (choice) 
     { 
     case 'I': getGames(array, k); break; 
     case 'D': displayGames(array, k); break; 
     case 'S': deleteGames(array, k); break; 
     case 'R': deleteGames(array, k); break; 
     case 'Q': kek = false; break; 
     default : cout << "Hey. Remember when I gave you the specific  options you were allowed to choose?" << endl; 
      cout << "Maybe enter one of those?" << endl; 
      cout << " " << endl; 
     } 
    } 
    while (kek); 
    cout << "You have killed me." << endl; 

} 
void getGames(VidyaGames array[], int &k) 
{ 
    system("cls"); 
    VidyaGames tmp; 
    char lel[100]; 
    cout << "Enter the title of your game: " << endl; 
    getline (cin, Title); 
    cout << "Enter the date your game was published: (Example: March 15th, 2014)" << endl; 
    getline (cin, Date); 
    cout << "Enter the developer of your game: " << endl; 
    getline (cin, Developer); 

    array->Title = Title; 
    array->Date = Date; 
    array->Developer = Developer; 
    k++; 


} 

void displayGames(VidyaGames array[], int &k) 
{ 
    system ("cls"); 
    if (k==0) 
     cout << "There is literally nothing in this list, as you have made the mental choice to not put anything in it yet." << endl; 


    else if (k > 0) { 
     for (int i=0; i < k; i++) 
     { 
      cout << "Title: " << array[i].Title << endl; 
      cout << "Release Date: " << array[i].Date << endl; 
      cout << "Developer: " << array[i].Developer << endl; 
     } 
    } 
} 


void deleteGames(VidyaGames array[], int &k) { 


    system("cls"); 
    char deleteChoice; 
    if (k==0) 
     cout << "There is literally nothing in this list, as you have made the mental choice to not put anything in it yet." << endl; 
    else { 
     cout << "Please type the name of the game you would like to delete: " << endl; 
     cin >> deleteChoice; 

    } 
} 

void sortGames(VidyaGames array[], int &k) 
{ 

} 
関連する問題