#include<iostream>
#include<string>
using namespace std;
float choice; //integer to hold a value to determine which fucntion the user wants by using an if statment
int
main()
{
float choice; //integer to hold a value to determine which fucntion the user wants by using an if statment
int string;
cout<<"Hello, please enter a string of text"<<endl;
cin>>string;
cout<<"You have 3 programs you may use\n";
cout<<"There is a letter counter, a letter sorter and a word counter\n";
cout<<"Please select which program you wish to use"<<endl;
cout<<"For letter counter type 1"<<endl;
cout<<"For letter sorter type 2"<<endl;
cout<<"For word counter type 3"<<endl;
cout<<"Please choose 1, 2 or 3"<<endl;
cin >> choice;
if(choice==1) {
cout<<"You have chosen char counting"<<endl;
}
else {
if(choice==2) {
cout<<"You have chosen char sorting;"<<endl;
}
else {
if(choice==3) {
cout<<"You have chosen char count;"<<endl;
}
//else { cout<<"Invalid selection please select 1,2 or 3"<<endl;}
Treat strings like you would any other variable. string naem;
Also, are you sure it's a good idea have choice as a floating point integer? Your comparisons shall not work; the constant integers are missing decimal points.
#include<iostream>
#include<string>
usingnamespace std;
float choice; //integer to hold a value to determine which fucntion the user wants by using an if statment
int
main()
{
float choice; //integer to hold a value to determine which fucntion the user wants by using an if statment
int string;
cout<<"Hello, please enter a string of text"<<endl;
cin>>string;
cout<<"You have 3 programs you may use\n";
cout<<"There is a letter counter, a letter sorter and a word counter\n";
cout<<"Please select which program you wish to use"<<endl;
cout<<"For letter counter type 1"<<endl;
cout<<"For letter sorter type 2"<<endl;
cout<<"For word counter type 3"<<endl;
cout<<"Please choose 1, 2 or 3"<<endl;
cin >> choice;
if(choice==1) {
cout<<"You have chosen char counting"<<endl;
}
else {
if(choice==2) {
cout<<"You have chosen char sorting;"<<endl;
}
else {
if(choice==3) {
cout<<"You have chosen char count;"<<endl;
}
//else { cout<<"Invalid selection please select 1,2 or 3"<<endl;}
}
}
return(0);
}
ok first you want shorten up your code a little bit so you have less useless lines
ex:
#include<iostream>
#include<string>
usingnamespace std;
float choice; //integer to hold a value to determine which fucntion the user wants by using an if statment
int //delete this line
main() // change to 'int main()'
{
float choice; //integer to hold a value to determine which fucntion the user wants by using an if statment
int string;// change string to 's' its easyer to work with to get the exact code that you want and you can easyly change it back later
cout<<"Hello, please enter a string of text"<<endl;
cin>>string;// read the comment on line 10
cout<<"You have 3 programs you may use\n";// you can delete all the extra 'cout's' and it can be all one line see ex2
cout<<"There is a letter counter, a letter sorter and a word counter\n";
cout<<"Please select which program you wish to use"<<endl;
cout<<"For letter counter type 1"<<endl;
cout<<"For letter sorter type 2"<<endl;
cout<<"For word counter type 3"<<endl;
cout<<"Please choose 1, 2 or 3"<<endl;
cin >> choice;
if(choice==1) {
cout<<"You have chosen char counting"<<endl;
}
else {
if(choice==2) {
cout<<"You have chosen char sorting;"<<endl;
}
else {
if(choice==3) {
cout<<"You have chosen char count;"<<endl;
}
//else { cout<<"Invalid selection please select 1,2 or 3"<<endl;}
}
}
return(0);
}
ex2:
1 2
cout<<"You have 3 programs you may use\nThere is a letter counter, a letter sorter and a word counter\nPlease select which program you wish to use.\nFor letter counter type 1.\nFor letter sorter type 2.\nFor word counter type 3.\nPlease choose 1, 2 or 3"<<endl;
cin >> choice;
this should beable to help save some space and if you do put this in toyour code and it fails then on the lines that i provided change to '.....\n.......' > to > '........\n" << ".......\n"<< etc.'
if it still fails pm me and i will try to figure out what needs to be changed but also try what everyone else is saying to good luck and hapy coding
@ packetpirate: I have noticed this but isn't float choice allowed I'm still kinda new at this and I'm learning as I go along personally i would rewrite this whole code but I also gotta remember that most of these questions are homework questions and I'm just programing for fun.