My IDE says "Errors exists in required project. Continue to launch?". at 48% through launch attempt. But doesn't show any highlighted errors.
Im using Eclipse indigo release 2.
Some other user said this something similar happened to them, and that they had deleted files from their hard drive recently, which i did but nothing in regards eclipse or c++.
#include <iostream>
#include <string>
using namespace std;
void search(char wrd2[26]);
bool srch(char wrd[26], char ch);
int pos(char wrd[26], char ch);
int cntr(char wrd[26], char ch);
void revr(char wrd2[26], char wrd1[26]);
void chcs(char wrd2[26], char wrd1[26]);
void re_ch(char wrd2[26], char wrd1[26]);
int main()
{
char wrd1[26], wrd2[26];
int opt=0;
cout<<"Please enter two word words."<<endl;
cout<<""<<endl;
cout<<"Please insert your first word here:";
cin>>wrd1;
cout<<""<<endl;
cout<<"Enter your second word here :";
cin>>wrd2;
cout<<endl;
do{
cout<<"Search enter 1:"<<endl;
cout<<endl;
cout<<"Reverse enter 2:"<<endl;
cout<<endl;
cout<<"Change the case enter 3:"<<endl;
cout<<endl;
cout<<"Reverse and change the case enter 4:"<<endl;
cout<<endl;
cout<<"Change your first word enter 5:"<<endl;
cout<<endl;
cout<<"Change your second word enter 6:"<<endl;
cout<<endl;
cout<<"Quit enter 7:"<<endl;
cin>>opt;
cout<<endl;
if (opt==1){
search(wrd2);
}
if (opt==2){
revr(wrd2,wrd1);
}
if (opt==3){
chcs(wrd2,wrd1);
}
if (opt==4){
re_ch(wrd2,wrd1);
}
if (opt==5){
cout<<"Please change your first word here:";
cin>>wrd1;
cout<<""<<endl;
}
if (opt==6){
cout<<"Please change your second word here:";
cin>>wrd2;
cout<<""<<endl;
}
}
while(opt !=7);
if(opt==7)
cout<<"good bye";
}
Does my code seems valid to you. Again there is no signs of errors on my IDE.
void search(char wrd2[26])
{ bool fnd=false;
char ch;
int x=0, cnt=0;
cout<<"Please enter in a character you would like to search for:";
cin>>ch;
cout<<""<<endl;
fnd=srch(wrd2,ch);
cnt=cntr(wrd2,ch);
x=pos(wrd2,ch);
if(fnd==true)
{
cout<<"Yes! Your character was found! :) ";
if(cnt==1)
{
if(x==0)
{
cout<<ch<<" is the "<<x+1<<"st letter of the word "<<wrd2<<".";
}
if(x==1)
{
cout<<ch<<" is the "<<x+1<<"nd letter of the word "<<wrd2<<".";
}
if(x==2)
{
cout<<ch<<" is the "<<x+1<<"rd letter of the word "<<wrd2<<".";
}
if(x>2)
{
cout<<ch<<" is the "<<x+1<<"th letter of the word "<<wrd2<<".";
}
cout<<" There is "<<cnt<<" letter "<<ch<<" in the word "<<wrd2<<"."<<endl;
cout<<" "<<endl;
}
if(cnt>1)
{
if(x==0)
{
cout<<"It first appears as the "<<x+1<<"st letter of the word. ";
}
if(x==1)
{
cout<<"It first appears as the "<<x+1<<"nd letter of the word. ";
}
if(x==2)
{
cout<<"It first appears as the "<<x+1<<"rd letter of the word. ";
}
if(x>2)
{
cout<<"It first appears as the "<<x+1<<"th letter of the word. ";
}
cout<<"There is "<<cnt<<" "<<ch<<"'s in the word "<<wrd2<<"."<<endl;
cout<<" "<<endl;
}
}
else
{
cout<<"Your character "<<ch<<" was not found in the word "<<wrd2<<". :("<<endl;
cout<<""<<endl;
}
}
bool srch(char wrd[26], char ch)
{
int x=0;
bool fnd=false;
for(x=0; x<=25; x++)
{
if(wrd[x]==ch)
{
fnd=true;
return fnd;
break;
}
}
if(!fnd)
{
return fnd;
}
return 0;
}
int pos(char wrd[26], char ch)
{
for(int x=0;x<26;x++)
{
if (wrd[x] == ch)
{
return x;
}
}
return 0;
}
int cntr(char wrd[26], char ch)
{
int cnt=0;
int x=0;
for(x=0;x<26;x++)
{
if (wrd[x] == ch)
{
cnt++;
}
}
return cnt;
return 0;
}
void revr(char wrd2[26],char wrd1[26])
{
int s,x;
s=strlen(wrd2)-1;
cout<<"Your second word "<<wrd2<<" reversed added to first = ";
cout<<wrd1;
for(x=s;x>=0;x--)
{
cout<<(wrd2[x]);
}
cout<<" "<<endl;
cout<<" "<<endl;
}
void chcs(char wrd2[26], char wrd1[26])
{
char ch;
int s,x;
s=strlen(wrd2)-1;
cout<<"Your second word with case changed proceeded by the first = ";
cout<<wrd1;
for(x=0;x<=s;x++)
{
if(wrd2[x]>= 65 && wrd2[x] <= 90) //is it upper?
ch=wrd2[x]+32;
else if(wrd2[x]>= 97 && wrd2[x] <= 122) //is it lower?
ch=wrd2[x]-32;
else
ch=1; //invlaid char - mark with smiley face
cout<<ch;
}cout<<endl;
}
void re_ch(char wrd2[26], char wrd1[26])
{
char ch;
int s,x;
s=strlen(wrd2)-1;
//cout<<"String with case changed = ";
cout<<"Your second reversed and with the case changed procceeded by the first"<<endl;
cout<<" "<<endl;
cout<<wrd1;
for(x=s;x>=0;x--)
{
if(wrd2[x]>= 65 && wrd2[x] <= 90) //is it upper?
ch=wrd2[x]+32;
else if(wrd2[x]>= 97 && wrd2[x] <= 122) //is it lower?
ch=wrd2[x]-32;
else
ch=1; //invlaid char - mark with smiley face
cout<<ch;
}cout<<" "<<endl;
cout<<" "<<endl;
}
What do i do?
I had a similar problem. Closing and reopening eclipse did it for me.
Related
I am trying to write a program which calculates the cost of a call based on the time the call was made, the day of the week and length of call. It has to be all call-by-value functions and output a option to repeat the program.
My problem is when I enter a invalid input for time such as a:37, it outputs invalid input but continues to the day input instead of returning to time entry. I am a new programmer and have tried everything I can think of to fix it but it either gets stuck in a infinite loop of exits the entire program.
Thanks in advance for any help!
#include <iostream>
using namespace std;
bool validateUserInputTime(int,char,int);
bool validateUserInputDay(string);
bool validateUserInputCallLength(int);
double calculateTotalCost(int,int,string,int);
string days[]={"Mo" , "Tu" , "We" , "Th" , "Fr" , "Sa" , "Su"};
float cost,fcost;
int main()
{
int hour;
int min;
int time;
char colon;
char answer = 'y';
string day;
string s;
bool result;
while(answer =='y')
{
cout<<"Enter the time the call starts in 24-hour rotation: "<<endl;
cin>>hour>>colon>>min;
result=validateUserInputTime(hour,colon,min);
if(cin.fail())
{
cout << "Invalid time input."<<endl;
cout<<"Please try again."<<endl<<endl<<endl;
cin.clear();
}
day=validateUserInputDay(s);
if(cin.good())
{
cout<<"Enter the first two letters of the day of the week:";
cin>>day;
}
cout<<"Enter the length of the call in minutes:"<<endl;
cin>>time;
result=validateUserInputCallLength(time);
if(result==0)
{
cout<<"Invalid minute Input."<<endl;
cout<<"Please try again."<<endl<<endl<<endl;
continue;
}
fcost= calculateTotalCost(hour,min,day,time);
cout<<"Cost of the call: $" << fcost<<endl;
cout<<"Do you want to repeat the program?";
cin>>answer;
}
return 0;
}
bool validateUserInputTime(int hour1,char ch,int min1)
{
if (cin.fail())
{
cout << "Invalid time input."<<endl;
cout<<"Please try again."<<endl<<endl<<endl;
cin.clear();
}
if(hour1 < 0)
{
return false;
}
if(min1 < 0)
{
return false;
}
if(ch!=':')
{
return false;
}
else
return true;
}
bool validateUserInputDay(string s)
{
int next=0;
for(int i = 0; i < 7; i++)
{
if(days[i] == s){
next=1;
}
if(cin.fail())
{
cout<<"Invalid day inpuT."<<endl;
cin.clear();
}
}
if(next==1)
{
return true;
}
else
{
return false;
}
}
bool validateUserInputCallLength(int time2)
{
if(time2<0)
{
return false;
}
else
{
return true;
}
}
double calculateTotalCost(int hour3,int min3,string d,int time3)
{
if((d=="Sa")||(d=="Su"))
{
cost=0.15*time3;
}
else
{
if((hour3>=8)&&(min3<18))
{
cost=0.40*time3;
}
else
cost=0.25*time3;
}
return cost;
}
Try using a loop. The loop will stop the program from progressing until the result value is true.
result = false;
while (!result)
{
cout<<"Enter the time the call starts in 24-hour rotation: "<<endl;
cin>>hour>>colin>>min;
result=validateUserInputTime(hour,colin,min);
}
You also forgot to put a false return statement on validateUserInputTime. Inputting non-digit characters might also crash the program, and cin.ignore happened to fix it.
if (cin.fail())
{
cout << "Invalid time input."<<endl;
cout<<"Please try again."<<endl<<endl<<endl;
cin.clear();
cin.ignore();
return false;
}
If you want to parse what the user entered do something like this instead
std::string time;
std::getline(std::cin, time);
now check if there is a ':' auto pos = time.find(':'); if (pos != -1) {}
then take out the hour part time.substr(0,pos)
then the minute part time.substr(pos+1)
then check if they are valid hour and minutes using e.g. stoi().
also it is better to do {} while () instead of while (answer == 'y') {...}
Please tell me how to check whether array is empty on not?
see my code after the step of code modify comment.I want a message "Sorry no value added so far".
#include<iostream>
using namespace std;
int count=0;
//----------------------------------------------------------//
//---------menu items list start from this position---------//
//----------------------------------------------------------//
void menu(int n){cout<<"\nEnter an option: \n";
cout<<"1- Add new value\n2- Search Value\n3- Modify value\n4- Print Value\n5- Print sum of all values\n6- Quit/terminate\n";
}
//-----------------------------------------------------------//
//---------Funtion to add new values starts from here--------//
//-----------------------------------------------------------//
void AddNewValue(int a[]){
cout<<"Enter a value\n";
cin>>a[count]; //taking input to array
count++;
}
//------------------------------------------------------------------------//
//---------Function to search a value from array starts from here---------//
//------------------------------------------------------------------------//
void SearchValue(int a[]){
int num,jawad=0;
cout<<"Enter a number to search\n";
cin>>num;
for(int starter=0;starter<count;starter++){ //starting loop from 1st value of array
if (num==a[starter])
jawad=1; //switching jawad from 0 to 1 if value found
}
if(jawad==1)
cout<<"value exists at "<<count<<"th position\n";
else cout<<"Value does not exist";
}
//-------------------------------------------------------------------//
//---------Function to modify value in array start from here---------//
//-------------------------------------------------------------------//
void ModifyValue(int a[]){
int modification,position;
cout<<"Enter the position of a number to modify";
cin>>position;
cout<<"Enter a number to modify";
cin>>modification;
a[position-1]=modification; //calculating index from enterd value and placing that equal to new number
}
//-----------------------------------------------------------//
//---------Function to Print values starts from here---------//
//-----------------------------------------------------------//
void PrintValue(int a[]){
cout<<"The stored values are : ";
for(int c=0;c<count;c++) //start loop and tak out all the values then print them
{cout<<a[c]<<' ';
if (a[c]==0)
cout<<"jawad adil";
}
}
//------------------------------------------------------------------------------//
//----------Function to Take sum of the values of array starts from here--------//
//------------------------------------------------------------------------------//
void PrintSum(int a[]){
int r=0,sum=0;
cout<<"The sum of all the values is : ";
while(r<count){
sum=sum+a[r]; //taking sum of all the values using loop
r=r+1;
}
cout<<sum<<'\n';
}
//---------------------------------------------//
//----------main body starts from here---------//
//---------------------------------------------//
int main(){
int n;
int a[100];
while(n!=6){
menu(n);
cin>>n;
if (n==1){
AddNewValue(a); //calling functions using if else statments
}
else if(n==2){
SearchValue(a);
}
else if(n==3){
ModifyValue(a);
}
else if(n==4){
PrintValue(a);
}
else if(n==5){
PrintSum(a);
}}
}
how can I do that? I am doing but it is not working.
You should add a "check" in your "modify" function.
Original:
void ModifyValue(int a[]){
int modification,position;
cout<<"Enter the position of a number to modify";
cin>>position;
cout<<"Enter a number to modify";
cin>>modification;
a[position-1]=modification;
With "check":
void ModifyValue(int a[]){
//Check
if(count == 0)
{
cout << "Sorry no value added so far";
return; //Exit from function
}
int modification,position;
cout<<"Enter the position of a number to modify";
cin>>position;
cout<<"Enter a number to modify";
cin>>modification;
a[position-1]=modification;
}
Also I recommend you to use switch instead of "if else if"
if (n==1){
AddNewValue(a); //calling functions using if else statments
}
else if(n==2){
SearchValue(a);
}
else if(n==3){
ModifyValue(a);
}
else if(n==4){
PrintValue(a);
}
else if(n==5){
PrintSum(a);
}
like:
switch (n)
{
case 1:
AddNewValue(a);
break;
case 2:
SearchValue(a);
break;
case 3:
ModifyValue(a);;
break;
//And so on...
default:
cout << "Unknown option";
}
Also in this code you don't need any arguments in
void menu(int n)
So you can make
void menu()
instead.
Also I recommend you to place whitespaces between operands and operators (words)
cout << "Enter a value\n";
cin >> a[count]; //taking input to array
count++;
instead
cout<<"Enter a value\n";
cin>>a[count]; //taking input to array
count++;
I want to know why I can't print record[i][1] using
puts (record[i][1]);
If I do:
cout<< record[i][1];
Then only the first letter of the string appears, not the rest.
This is for a school project.
I code on Turbo C++ (TC4).
#include< fstream.h>
#include< strstream.h>
#include< conio.h>
#include< dos.h>
#include< graphics.h>
#include< string.h>
#include< stdio.h>
#include< stdlib.h>
#include< string.h>
#include< ctype.h>
#include< iomanip.h>
#include< iostream.h>
char record[500][5]; //array to store 500 entries each consisting of
//name,cell no, agesex, crime and sentenced.
int cricode=1;
char name[35];
char criminalno[10];
char agesex[5];
char sentenced[3];
char crime[20];
char passwordU[30];
int checkpass(char[]);
void menu(int);
void advmenu(int);
void inputdata();
void report(int) ;
void searchrecN(char [][5], int);
void searchrecC(char [][5], int);
void selectcrime(char []);
void changepass();
void displaydata(int);
void main()
{
clrscr();
ifstream fp;
fp.open("criminal.txt");
do
{char a;
fp.getline(&record[cricode][1],30,'!') ; //name
fp.getline(&record[cricode][2],10,'#'); //cellno
fp.getline(&record[cricode][3],7,'%'); //agesex
fp.getline(&record[cricode][4],20,'^'); //crime
fp.getline(&record[cricode][5],3,'\n'); //sentenced
cricode++ ;
}while (fp.eof() == 0);
cricode--; //final value of cricode
fp.close();
menu(cricode);
getch();
}
void menu(int code)
{
fstream fp;
int hell;
clrscr();
cout<<"\n\n";
cout<<"______________________________________\n";
cout<<" L O C A L M E N U \n";
cout<<"______________________________________\n";
cout<<"\n\n";
cout<<"\t\t\t"<<"\n\n[1] Create a Record.";
cout<<"\t\t\t"<<"\n\n[2] Search for a record.";
cout<<"\t\t\t"<<"\n\n[3] Advance Options.";
cout<<"\t\t\t"<<"\n\n[4] Display all entries.";
cout<<"\t\t\t"<<"\n\n[5] Exit \n :";
cin>>hell;
switch(hell)
{
case 1: clrscr();
inputdata();
system("pause");
menu(code);
break;
case 2: clrscr();
char na[30];
int ch;
clrscr();
cout<<"\t\t\t"<<"\nSearch by -> ";
cout<<"\t\t\t\t"<<"\n[1] Name : ";
cout<<"\t\t\t\t"<<"\n[2] Cell No. : ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\n Please Enter Name : ";
//gets(na);
searchrecN(record,code);
break;
case 2:
cout<<"\n Please Enter Cell No. : ";
//gets(na);
searchrecC(record,code);
break;
default : cout<<"invalid";
}
menu(code);
break;
case 4: clrscr();
for(int i=0;i<code;i++)
{
cout<<"\nName \t Cellno \t age/sex \t crime \t sentenced \n";
cout<<record[i][1]; //only one character is displayed of the
// entire word.
// if i do
//puts(record[i][1]); // Error: cannot convert 'int' to 'const char *'
}
cout<<"\n";
system("pause");
menu(code);
break;
case 5: //clrscr();
//intro();
break;
default:
cout<<"\a";
}
}
int i;
void report(int cc)
{
cout <<record[cc][1]<<"\t"
<<record[cc][2]<<"\t"
<<record[cc][3]<<"\t"
<<record[cc][4]<<"\t"
<<record[cc][5]<<"\n";
}
void inputdata()
{
char ch;
char recname[30],reccell[10],recagex[7],recrime[20],recsent[3];
ofstream fp;
fp.open("criminal.txt", ios::app);
do
{
cout<<"\n[.] Name : ";
gets(recname);
cout<<"\n[.] Criminal Number : ";
gets(reccell);
cout<<"\n[.] Age/Sex {eg: 21/M} : ";
gets(recagex);
cout<<"\n[.] Select Crime : ";
selectcrime(recrime);
cout<<"\n[.] Sentenced For : ";
gets(recsent);
fp <<recname
<<"!"<<reccell
<<"#"<<recagex
<<"%"<<recrime
<<"^"<<recsent
<<"\n";
cout<<"Do you Want to Continue(Y/N): ";
cin>>ch;
}while((ch=='y')||(ch=='Y'));
system("pause");
}
void searchrecN(char record[][5], int cricode)
{
int cnt;
char search[30];
cout<<"Enter Cellno.: ";
gets(search);
for(i=0;i<cricode;i++)
{
if (strcmpi(search,&record[i][1])==0)
{
clrscr();
cout<<"\nRecord Found.";
cout<<"\nLoading Info......";
system("pause");
report(i);
cnt=1;
break;
}
}
if(cnt==0)
{
clrscr();
cout<<"\n ***Record does not exist*** ";
cout<<"\n ***Redirecting***\n";
system("pause");
}
}
void searchrecC(char record[][5], int cricode)
{
int cnt;
char search[10];
cout<<"Enter Cellno.: ";
gets(search);
for(i=0;i<cricode;i++)
{
if (strcmpi(search,&record[i][2])==0)
{
clrscr();
cout<<"\nRecord Found.";
cout<<"\nLoading Info......";
system("pause");
report(i);
cnt=1;
break;
}
}
if(cnt==0)
{
clrscr();
cout<<"\n ***Record does not exist*** ";
cout<<"\n ***Redirecting***\n";
system("pause");
}
}
void displaydata(int c)
{
clrscr();
fstream fp;
for(i=0;i<c;i++)
{
cout<<"Name\tCellno\tage/sex\tcrime\tsentenced";
cout <<record[i][1]<<"\t"<<record[i][2]<<"\t"
<<record[i][3]<<"\t"<<record[i][4]<<"\t"
<<record[i][5]<<"\n";
}
/* cout<<setw(100)<<"\n[.] Criminal No. : ";
puts(record[i][2]);
cout<<setw(100)<<"\n[.] Age/Sex : ";
puts(record[i][3]);
cout<<setw(100)<<"\n[.] Alleged for : : ";
// puts(obj[i].category);
cout<<setw(100)<<"\n[.] Crime : ";
puts(record[i][4]);
// cout<<setw(100)<<"\n[.] Expenses per month : ";
puts(record[i][4]);
/* cout<<setw(100)<<"\n[.] Expenses per Month : ";
cout<<exp;
cout<<setw(100)<<"\n[.] Sentenced for : ";
puts(record[i][5]); */
}
Your record array is an array of 500 rows of 5 single characters, not 5 strings.
I recommend you model your data with a structure:
struct Record
{
char name[35];
char criminalno[10];
char agesex[5];
char sentenced[3];
char crime[20];
char passwordU[30];
};
Your database can then be 500 records:
Record database[500];
FYI, safer and less troublesome techniques are to use std::string and std::vector.
Why is the following code not giving results and how to get results?
Whenever I run the code, it first asks for the names of the players of two teams playing the match, then it shows the menu from which if we select any one of the option it again asks for the batsman name which is not according to the program designed. My research on the code and the problem is that I think buffer memory is full but I don't know how to free it, any help would be beneficial. Thank you
#include<iostream>
#include<string.h>
#include<conio.h>
using namespace std;
class scorecard{
char batname[11][20];
int runscored[11];
char situation[11][10];
char mode[11][15];
char bowlername[11][20];
float oversplayed[11];
int maiden[11];
int runsgiven[11];
int wicketstaken[11];
public:
void updatebatsman(void);
void updatebowler(void);
void displaybat(void);
void displaybowl(void);
void menu(void);
scorecard()
{for(int n=0;n<12;n++)
{
runscored[n]={0};
oversplayed[n]={0};
maiden[n]={0};
runsgiven[n]={0};
wicketstaken[n]={0};
}
}
};
int main()
{
int jb=0;
scorecard s1;
int kb;
s1.menu();
do
{
cout<< "Enter the option"<<endl;
cout<<"(1) Display batting score"<<endl<<"(2) Display Bowling score"<<endl<<"(3) Update batting score"<<endl;
cout<<"(4) Update Bowling score"<<endl;
cin >>kb;
switch(kb)
{
case 1 : s1.displaybat();
break;
case 2 :s1.displaybowl();break;
case 3:s1.updatebatsman();break;
case 4:s1.updatebowler();break;
default:cout<<"Wrong choice";
}
}while (jb<1);
}
void scorecard::updatebowler(void)
{char bowlname[20];
int str,k,option,overnumbers,maidenumb,uprun,upwicket;
cout<<"Enter Bowler name:";
cin.getline(bowlname,20);
for( k=0;k<11;k++)
{str= strcmp(bowlername[k],bowlname);
if (str== 0)
{
cout<<"Menu for Bowler information update "<<endl;
cout<<"(1) Update Number of overs"<<endl<<"(2) Update maiden overs"<<endl<<"(3) Update runs given"<<endl;
cout<<"(4) Update wickets taken"<<endl;
cin >> option;
switch(option)
{
case 1:{cout<<"Enter Numbers of overs to be updated:";
cin >>overnumbers;
cout<<endl;
oversplayed[k]+=overnumbers;
break;
}
case 2:{cout <<"Enter the number of maiden overs to be updated:";
cin>>maidenumb;
cout<<endl;
maiden[k]+=maidenumb;
break;
}
case 3:{cout <<"Enter the number of runs to be added:";
cin>>uprun;
cout<<endl;
runsgiven[k]+=uprun;
break;
}
case 4: {cout<<"Enter number of wickets to be updated:";
cin >>upwicket;
cout<<endl;
wicketstaken[k]+=upwicket;
}
default:cout<<"wroung choice";
}
break;
}
}
if (str!=0)
cout <<"You entered wrong player."<<endl;
}
void scorecard::updatebatsman(void)
{char batsmaname[20];
int str,k;
cout<<"Enter Batsman name:";
cin.getline(batsmaname,20);
for( k=0;k<11;k++)
{str= strcmp(batname[k],batsmaname);
if (str== 0)
{
cout<<"enter runs scored:";
cin>>runscored[k];
cout<<endl<<"enter weather out or not out:";
cin>>situation[k];
cout<<endl<<"enter mode(if batsman out) by which batsman was out:";
cin>>mode[k];
break;
}
}
if (str!=0)
cout <<"You entered wrong player."<<endl;
}
void scorecard::displaybat(void)
{
cout << "Batsman name"<<'t'<<"Runs scored"<<'t'<<"situation"<<'t'<<"mode"<<endl;
for(int j=0;j++;j<12)
{
cout<<batname[j]<<'t'<<runscored[j]<<'t'<<situation[j]<<'t'<<mode[j]<<endl;
}
}
void scorecard::displaybowl(void)
{
cout << "Bowler name"<<'t'<<"overs played"<<'t'<<"maiden overs"<<'t'<<"wicket taken"<<'t'<<"Runs given"<<endl;
cout<<endl;
for(int j=0;j++;j<12)
{
cout<<bowlername[j]<<'t'<<oversplayed[j]<<'t'<<maiden[j]<<'t'<<wicketstaken[j]<<'t'<<runsgiven[j]<<endl;
}
}
void scorecard::menu(void)
{
cout<<"Enter the name of players of batting team"<<endl;
for (int k=0;k<11;k++)
{
cout <<"Enter name of player "<<k+1<<":";
cin>>batname[k];
}
cout <<"Enter the name of players of bowling team"<<endl;
for (int n=0;n<11;n++)
{
cout <<"Enter name of player "<<n+1<<":";
cin>>bowlername[n];
}
}
This is very wrong:
for(int j=0;j++;j<12)
It should be:
for(int j=0; j < 11; j++)
You are also missing a break in your case 4 statement for the options:
case 4: {cout<<"Enter number of wickets to be updated:";
cin >>upwicket;
cout<<endl;
wicketstaken[k]+=upwicket;
break;
}
default:cout<<"wroung choice";
Without the break you will see also the output wrong choice when the user selects option 4.
How can I compare character regardless of its case. Means suppose I enter Z if my if condition shall return true for both Z and z, character can be any alphabet from A-Z or a-z.
Like ABCbabcAABC
If I enter B then it I must get 4 as output because there are 4 B in string.
I am learning C++ on Turbo C++. I am trying to do but now not getting way out.
void main()
{
clrscr();
char str[50],ch;
char str1[50];
int i = 0, l;
cout << "Enter strings: ";
gets(str);
cout << "Enter charcter: ";
cin >> ch;
l = strlen(str);
for(i = 0; i <= l; i++)
{
cout << isupper(str[i]) ? tolower(str[i]) : toupper(str[i]);
}
puts(str);
getch();
}
void main()
{
clrscr();
char str[50],ch;
char str1[50];
int i=0,l;
cout<<"Enter strings: ";
gets(str);
cout<<"Enter charcter: ";
cin>>ch;
l=strlen(str);
int result=0;
for(i=0;i<l;i++)
{
if(tolower(ch)== tolower(str[i]))
{
result++;
}
}
puts(str);
puts(result);
getch();
}
if (tolower(str[i]) == tolower(ch)) {
cout << (isupper(str[i]) ? tolower(str[i]) : toupper(str[i]));
} else {
cout << str[i];
}
40000 is the isupper output. Non zero for an upcase char, zero for lowercase, as written in manual
All you need to do is to play around with the ASCII value.
Check out the code: which explains that you need to convert only those characters whoce ASCII value is between 65(A) to 90(Z).
public class Ques2 {
/**
* #param args the command line arguments
*/
public static void main(String[] args) throws IOException {
//ascii A=65 Z=90 a=97
System.out.println("Enter UPPERCASE");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// String input = br.readLine().toLowerCase();
char c;
char[] word=br.readLine().toCharArray();
for(int i :word)
{
if(i>=65 && i<=90){
i=i+32 ;
c=(char) i;
System.out.println(c);
}
else{
c=(char)i;
System.out.println(c);
}
}
}
}