Error finding in function and related code – CSKC
Sign In

Search

Solved Problem #CPP#4447    siteicon   siteicon  

Problem Statement - Error finding in function and related code

Find syntactical errors in the following program and rewrite the program after underlining the corrected portion.

#include<iostreamh>
using namespace std;
void toUpper(char x) {return ((char) (x+1));}
main()
{
char c, String[]=”DOGS ARE NOT CATS”;
for(int i=0;String[i]!=;i++)
if(String[i]==’ ‘) cout<<endl;
else { c=toUpper(String[i]);cout<<c;}
return 0;
}

Solution

TC++ #4447

 

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

#include<iostream.h>  //Needs to include header file properly as iostream.h or iostream
using namespace std;
char toUpper(char x){return ((char) (x+1));} //Must return char type as return type is casted as char
int main() //must have a return type as int as return 0 is given in the end.
{
char c, String[]=”DOGS ARE NOT CATS”;
for(int i=0;String[i]!=”;i++)   //must include single quote for null character
if(String[i]==’ ‘) cout<<endl;
else { c=toUpper(String[i]);cout<<c;}
return 0;
}

Common Errors

  • Student often forgets to check for the return type of a function to match the exact return type assigned in the return statement.


Share

Created: 24-Aug-2018 00:57 | Updated: 22-Mar-2026 20:22|