Im reading tutorials and whatnot, and im trying to get used to creating my own functions.
Now this may not be a function error, i dunno. But until i added the function sections i was doing fine. Basically a tutorial gave me "homework" so i tried to do it, and failed . What im sposed to do is make a program to have the user input a number between 1 and 20, and once inputted the program uses if statements to check if its between 1 and 10, or between 11 and 20. The first if will use a function that just messages the user, the other function takes the users input and adds 35 to it.
Thanks for any help and forgive my n00b ignorance lol. Also keep note my coding "style" is none existant seeing as im learning from whatever tutorial explains the topic at hand in a way i get best.
Code:
#include <iostream>
#include <string>
using namespace std;
void ztot()
{
cout<<"You number was between 1 and 10."<<endl;
}
void ttot(int y)
{
int c = y + 35;
cout<<y<<" was your number, "<<y<<" + 35 = "<<c<<"."endl;
}
int main()
{
string T = "Please type a Number between 1 and 20";
cout<<T<<endl;
int x, y;
while (!(cin>>x)){
cout<<"You can only use numbers for this."<<endl;
cin.clear();
cin.ignore(1000,'\n');
cout<<T<<endl;
}
while((x < 1) || (x > 20)){
cout<<"You have inputed a number not in the range of 1-20."<<endl;
cin.clear();
cin.ignore(1000,'\n');
cout<<T<<endl;
}
if(x <= 10){
ztot();
}else{
ttot(x);
}
// cout<<x<<endl;
cin.ignore();
cin.get();
}
Error:
helloworld.cpp: In function `void ttot(int)':
helloworld.cpp:12: error: syntax error before `;' token
make.exe: *** [helloworld.o] Error 1
Execution terminated
Side note, is there anything wrong with anything im using? Such as void, endl, the cin.ignore/get combo. ect. I dont fully comprehend the whole flushing and needing to ignore. Same with in the while loops how you clear, which in my description says it clears all text, then you gatta use something again to clearn the text "cin.ignore(1000,'\n');". Anyway, thanks for the help