You are not logged in.
Pages: 1
#include <iostream>
using namespace std;
int main() {
int d = -1;
int n;
int q;
int r;
cout << "Enter the numerator (top number)";
cin >> n;
while (d == 0 || d == -1) {
if (d == 0) {
cout << "You can't divide by 0";
}
cout << "nEnter the denominator (bottom number)";
cin >> d;
cout << "n";
}
q = n / d;
r = n % d;
cout << "nThe quotient with remainder is " << q << " R" << r;
q = 1.0 * n / d;
cout << "nThe quotient is " << q;
return 0;
}
project2_1.cpp: In function `int main()':
project2_1.cpp:31: warning: converting to `int' from `double'
/tmp/ccBBSb6P.o(.text+0xd): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
/tmp/ccBBSb6P.o(.text+0x60): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccBBSb6P.o(.text+0x9f): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccBBSb6P.o(.text+0xce): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/ccBBSb6P.o(.text+0x12e): In function `main':
: undefined reference to `std::cout'
/tmp/ccBBSb6P.o(.text+0x133): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccBBSb6P.o(.text+0x141): In function `main':
: undefined reference to `std::cin'
/tmp/ccBBSb6P.o(.text+0x146): In function `main':
: undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'
/tmp/ccBBSb6P.o(.text+0x169): In function `main':
: undefined reference to `std::cout'
/tmp/ccBBSb6P.o(.text+0x16e): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccBBSb6P.o(.text+0x17d): In function `main':
: undefined reference to `std::cout'
/tmp/ccBBSb6P.o(.text+0x182): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccBBSb6P.o(.text+0x190): In function `main':
: undefined reference to `std::cin'
/tmp/ccBBSb6P.o(.text+0x195): In function `main':
: undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(int&)'
/tmp/ccBBSb6P.o(.text+0x1a4): In function `main':
: undefined reference to `std::cout'
/tmp/ccBBSb6P.o(.text+0x1a9): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccBBSb6P.o(.text+0x1e8): In function `main':
: undefined reference to `std::cout'
/tmp/ccBBSb6P.o(.text+0x1ed): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccBBSb6P.o(.text+0x1fe): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
/tmp/ccBBSb6P.o(.text+0x20e): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccBBSb6P.o(.text+0x21f): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
/tmp/ccBBSb6P.o(.text+0x24e): In function `main':
: undefined reference to `std::cout'
/tmp/ccBBSb6P.o(.text+0x253): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccBBSb6P.o(.text+0x264): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
/tmp/ccBBSb6P.o(.text+0x28d): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init()'
/tmp/ccBBSb6P.o(.text+0x2be): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccBBSb6P.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
I have no idea whats going on. Haven't had a chance to play with any other compilers yet, dunno if its my computer, probably my code. I miss java :oops:
thanks
"Ignorance is bliss, for stupid people."
"open-source is [...] programming Darwinism."
Vaughan-Nichols
Offline
try g++
Offline
sorry I should have been more clear...
g++ will compile c++ files while gcc is C.
when you do g++ nameoffile.cpp it spits out an a.out executable. If you want to change that you can do
g++ -o nameofoutputfile nameoffile.cpp
and the executable will be nameofoutputfile.
Offline
or you can just type make and it will use the correct gnu compiler for you
Offline
or you can just type make and it will use the correct gnu compiler for you
Doesn't that require writing a makefile??
Offline
Another problem with your code is that you declare q as an integer:
int q;
but you give it a double value:
q = 1.0 * n / d;
Offline
Another problem with your code is that you declare q as an integer:
int q;
but you give it a double value:
q = 1.0 * n / d;
ah crap, thats why it wasnt working. stupid me...
thanks for the help everyone, works now
"Ignorance is bliss, for stupid people."
"open-source is [...] programming Darwinism."
Vaughan-Nichols
Offline
Dusty: Yes, it requires a Makefile.
Offline
Actually no, its not needed. you can just type make project2_1
I just tested it on a random c file:
[sgillespie@SG-Arch01 cApps]$ make strTest
cc strTest.c -o strTest
Offline
Well I'll be. I stand corrected
Offline
wow, that's cool.
Dusty
Offline
Who says you don't learn something new everyday?
I stole that idea from phrakture who responded with this a long time ago on a similar question.
Offline
Who says you don't learn something new everyday?
I stole that idea from phrakture who responded with this a long time ago on a similar question.
I remember that too but I could never get it to work....didn't realize you had to leave off the extension.
Offline
Yep, I figured that out earlier today.
It says that nothing can be done or something.
Offline
Euphoric Nightmare wrote:Who says you don't learn something new everyday?
I stole that idea from phrakture who responded with this a long time ago on a similar question.
I remember that too but I could never get it to work....didn't realize you had to leave off the extension.
Yeah, it's cool... but be careful with it... you almost always want to compile with -Wall, but "make myprog" won't do that.... unless you do "make CFLAGS=-Wall myprog"
Offline
Pages: 1