Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > (newbie question)How come my program won't run?

(newbie question)How come my program won't run?
Thread Tools
Forum Regular
Join Date: Jan 2001
Location: Flushing, NYC
Status: Offline
Reply With Quote
Apr 3, 2001, 11:21 AM
 
OK, here is my dilemma. I have been using Visual C++ on Winblows (as required by my school, bleh) and have recently bought a Ti and Mac OS X. Since I purchased the "future of computing", I can't seem to find a way for Project Builder to compile and run my program. It worked fine under Visual Basic C++ and been doing all sorts of things to try to have it run under PB. I looked at this topic http://forums.macnn.com/cgi-bin/Foru...ML/000706.html and tried to compile it under UNIX with success. However, I was wondering if someone out there could help me compile this program under PB. Here is the simple program:

//Kenneth Woo
//CIS 3100 Section KM14
//Programming Assignment 1
//Some Statistical Analysis

# include <iostream>
using namespace std;
# include <cmath>
using namespace std;
int main ()
{
float A, B, C, D, E, F, G, sum, mean, variance;
cout<<"I will give you the sum, mean, and ";
cout<<"standard deviation of any seven numbers. \n";
cout<<"Type each number, followed by the enter key. \n";
cout<<"1st number = ? \n";
cin>>A;
cout<<"2nd number = ? \n";
cin>>B;
cout<<"3rd number = ? \n";
cin>>C;
cout<<"4th number = ? \n";
cin>>D;
cout<<"5th number = ? \n";
cin>>E;
cout<<"6th number = ? \n";
cin>>F;
cout<<"7th number = ? \n";
cin>>G;
cout<<endl;
//Now for the Equations
sum = (A+B+C+D+E+F+G);
mean = (sum) / 7.0;
variance = ((A-mean)*(A-mean)+(B-mean)*(B-mean)+(C-mean)*(C-mean)+
(D-mean)*(D-mean)+(E-mean)*(E-mean)+(F-mean)*(F-mean)+
(G-mean)*(G-mean)) / 6.0;
//Now for the output
cout<<"The numbers you have typed in are " <<A<<", "<<B<<", ";
cout<<C<<", "<<D<<", "<<E<<", "<<F<<", and "<<G<<"." <<endl<<endl;
cout<<"The sum is " <<sum<<endl<&am p;lt;endl;
cout<<"The mean is " <<mean<<endl<&a mp;lt;endl;
cout<<"The variance is " <<variance<<endl&l t;<endl;
cout<<"The standard deviation is " <<sqrt(variance)<<endl <<endl;
return 0;
}

Would I need to obtain the iostream header file? How would I get it? How do I get PB to build correctly (this is the error I usually get). Thanks!

------------------
That's the power of this...and that's what Apple has really put into our hands. It's not about new technology, it's not about a new toy or a new box....It's a whole new way of thinking. - Jon Kamen, Proprietor@radical.media on the Powerbook G4
     
Mac Elite
Join Date: Sep 2000
Location: Eagan, MN
Status: Offline
Reply With Quote
Apr 3, 2001, 02:01 PM
 
I've heard that console apps that use cin won't run correctly when compiled with PB.

And why is your school using Visual C++ to do console apps? You should be using Borland Turbo C++.

------------------
     
Forum Regular
Join Date: Jan 2001
Location: Flushing, NYC
Status: Offline
Reply With Quote
Apr 3, 2001, 09:08 PM
 
Well, according to my professor, my school did use Borland in the past but recently switched to Visual C++ due to the dominance of Windows. My professor tells the class on a regular basis how he hates the new department policy but since my school is heavily business-orientated, he has no choice. Is there a substitute for cin? Please help me cause I really hate using Visual C++. I just love programming in Project Builder but I will be forced to move over to VB if the cin does not work. Thanks for the reply, mr_sonicblue.

PS - I would also love to show MAC OS X in action with PB and show my professor how far macs have come, hence my problem.....
     
Mac Elite
Join Date: Sep 2000
Location: Eagan, MN
Status: Offline
Reply With Quote
Apr 3, 2001, 10:07 PM
 
Sorry, but I don't know if there's an alternative. Does the C function fscan() exist on Mac? That's what we used in Borland before we learned objects.

------------------
     
Mac Elite
Join Date: Sep 2000
Location: Eagan, MN
Status: Offline
Reply With Quote
Apr 3, 2001, 10:16 PM
 
I checked and I don't see the stdio header. So much for fscan

------------------
     
Mac Elite
Join Date: Sep 2000
Location: Eagan, MN
Status: Offline
Reply With Quote
Apr 3, 2001, 10:20 PM
 
OK, scratch that! I looked again and it's there. It's been renamed to "cstdio" which simply includes "stdio.h".

------------------
     
Forum Regular
Join Date: Jan 2001
Location: Flushing, NYC
Status: Offline
Reply With Quote
Apr 4, 2001, 05:55 AM
 
sonic_blue, thank you for your input....ok, i tried the cstdio with the header stdio.h with no results. It shows that it builds successfully but yet again no output window. I'm going to try to pick new project options (like trying an empty project instead of C++ tool, vice versa), which I will try later.
     
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Apr 4, 2001, 06:03 AM
 
Instead of cin you can use scanf(). It is used very similarly to printf(). It is part of C, not C++. cin and cout are C++ things. Anyway, scanf() and printf() will still work in anything that you make using C++. I prefer using printf for formatted output much better than the stuff in iomanip.h. Running console bases apps in Project builder is kind of flaky. If it doesn't work for you then run them from the command line. Here is an example of using printf and scanf:

#include <stdio.h>

int main()
{
int number;
printf("Please Input a number");
scanf("%i", number);
printf("You inputted %i as your number", number);
return 0;
}


Another function to know is fflush, which you can use to flush your buffers. For example, fflush(stdout); flushes the output buffer and fflush(stdin); flushes the input buffer. Think of it like cout << flush; or cin >> flush; The big problem with console io in OS X is that cout doesn't flush the output buffer until a newline is reached. This means that endl will make it flush the buffer, flush won't and it also won't automatically flush the buffer when you take input, but I believe that it will do it immediately after you take input. printf and scanf work fine so just use them and don't worry about it.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:53 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2