In class we need to rewrite code into OOP and the book assigned goes against it but i'm trying to figure out how to properly get the Give me a Number program to ask and give a number. After which I plan on adding a function overloading. But what i'm not getting is that you really can't add in:
int askNumber(int high, int low)
after
int askNumber(int high, int low = 1);
without getting a error because its being used more than once in the same class.
This is what I have so far up to the error, at the moment i'm still reading through the book and researching on possible solutions.
// Get my number HW.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "string"
#include "iostream"
usingnamespace std;
class myNumber{
int askNumber(int high, int low = 1);
int numberOut(){
int number = askNumber(5);
cout<< "Thanks for entering: " << "\n\n" << endl;
number = askNumber(10, 5);
cout << "Thanks for entering: " << "\n\n" << endl;
}
// error of being stated twice
int askNumber(int high, int low){
int num;
do {
cout << "Please enter a number " << " ( " << low << " - " << high << " ): ";
cin >> num;
}while (num > high || num < low);
return num;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
myNumber get;
return 0;
}
Aw man I should really kick my self for over thinking that. Thanks I got it working.
I also wanted to see if someone could give me a hint on how to properly triple a inputted string.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
//out of the class (at least where the book says its suppose to be)
int triple(int number);
string triple(string text);
//
void tripleLoad(){
string text;
cout << "Type a word to repeat three times: " << triple(text);
cin >> text;
}
string triple(string text)
{
return (text + text + text);
}
I know if I just replace inside the ( ) with for example ( "dog ") it'll triple the word. But for ever reason when I type in a word/number it'll output the word but won't triple it.