Same Code compiled sucessfully on a desktop but failed on a laptop  
Author Message
SamSam698





PostPosted: Visual C++ General, Same Code compiled sucessfully on a desktop but failed on a laptop Top

Hi there,

I encountered a very strange problem as mentioned above.Below is the source code:

#include<iostream>
#include<string>


using std::cout;
using std::cin;
using std::endl;
using std::string;

struct CindyBar{

string brand;
float weight;
int calory;

};


int main(){

cout<<"Plesae enter the size to determine the array:\n";
int size;
(cin>>size).get();

CindyBar *snack=new CindyBar[size];


cout<<"Please enter the items one by one:\n";

for(int i=0;i<size;i++){
cout<<"Please enter the No."<<i+1<<" 's brand:\n";
getline(cin,snackIdea.brand);
cout<<"Pleae enter the No."<<i+1<<" 's weight:\n";
(cin>>snackIdea.weight).get();
cout<<"Please enter the No."<<i+1<<" 's calory:\n";
(cin>>snackIdea.calory).get();

}

int i=0;
while(i!=size){
cout<<snackIdea.brand<<"\t"<<snackIdea.weight<<"\t"<<snackIdea.calory<<endl;
i++;}

delete [ ]snack;
system("PAUSE");
return 0;
}

It was built sucessfully on a desktop but failed on my compaq laptop.The message said that the problem cocurred due to the 'size' variable=>array snack's size is undefined.

Could you please let me know how come

Regards,

Sam




Visual C++5  
 
 
cgraus





PostPosted: Visual C++ General, Same Code compiled sucessfully on a desktop but failed on a laptop Top

I've marked this topic off topic so it will eventually be deleted. Please don't repost the same questions, and especially not within 20 minutes of each other. If you don't get an answer, reply to your own topic to bump it back up the unanswered list.