c++ - Storing values in arrays -


the user supposed enter name followed grades. when user hits -1 there can no more grades stored individual. when user types x, s/he enters total , -1 indicate no more grades can stored. don't understand why loops outputting in weird way. names array storing int values supposed go numbers array.

for example, input should this:

jane 3 4 -1 lane 4 5 -1 x   10 10 -1  

the output should this:

jane 3 4  jane had 7/20 lane 4 5 lane had 9/20 

this work far:

#include <iostream> #include <cstring> #include <string>  using namespace std;  int main() {  string name = " ";  string names[20];  int numbers[20];  int = 0, j=0, number;    {    cin >> name;    names[i]=name;    i++;     j=0;    if(number!=-1)    {        cin>> number;        numbers[j]=number;        j++;    }  }while(name!="x");   for(int x = 0; x <= i; x++)  {   for(int y = 0; y <= j; y++)   {       cout << names[x];   }  }  } 

one issue code ,

 int = 0, j=0, number; 

you use uninitialised number in code

if(number!=-1) 

this contains garbage values can co-incidentally -1


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -