| | |
can't get fee
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Sep 2007
Posts: 4
Reputation:
Solved Threads: 0
hi ,
i'm writing a program which calculates registration fee of student and this program opens an external txt file.It's my first time writing a program with an input file so i'm kinda confused.my program asks for the status and number of credits but does not gimme the fee.
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdlib>
#include<conio.h>
#include<cmath>
using namespace std;
int main()
{
string filename = "registration fee.txt";
ifstream inFile;
int n;
double fee;
char response1,response2;
char i,o,u,g;
inFile.open("registration fee.txt");
cout<<"please enter your status of residence,type i or o"<<endl;
cin>>response1;
cout<<"please enter your status of study,type u or g"<<endl;
cin>>response2;
cout<<"please enter your number of credits"<<endl;
cin>>n;
i = 0;
u = 0;
if ((response1 == i)&& (response2 == u))
{
if (n < 12)
{
fee = ((280 *n *0.35)+ (43 * n));
cout<<"status of residence : " << response1<<endl;
cout<<"status of study : "<<response2<<endl;
cout<<"number of credits : "<<endl;
cout<<fee<<endl;
if (n >= 12)
{
fee = ((280 *n *0.35)+ (43 * 12));
cout<<"status of residence : " << response1<<endl;
cout<<"status of study : "<<response2<<endl;
cout<<"number of credits : "<<endl;
}
}
}
g = 0;
if((response1 == i) && (response2 == g))
{
if (n < 9)
{
fee = (400 * n * 0.35) + (43 * n) + 10;
cout<<"status of residence : " << response1<<endl;
cout<<"status of study : "<<response2<<endl;
cout<<"number of credits : "<<endl;
cout<<fee<<endl;
if (n >= 9)
{
fee = (400 * n * 0.35) + (43 * 9) + 10;
cout<<"status of residence : " << response1<<endl;
cout<<"status of study : "<<response2<<endl;
cout<<"number of credits : "<<endl;
cout<<fee<<endl;
}
}
}
o = 1;
if ((response1 == o)&& (response2 == u))
{
if (n < 12)
{
fee = (280 * n) + (43 * n);
cout<<"status of residence : " << response1<<endl;
cout<<"status of study : "<<response2<<endl;
cout<<"number of credits : "<<endl;
cout<<fee<<endl;
if (n >= 12)
{
fee = (280 * n) + (43 * 12);
cout<<"status of residence : " << response1<<endl;
cout<<"status of study : "<<response2<<endl;
cout<<"number of credits : "<<endl;
cout<<fee<<endl;
}
}
}
if ((response1 == o) && (response2 == g))
{
if (n < 9)
{
fee = (400 * n * 0.35) + (43 * n) + 10;
cout<<"status of residence : " << response1<<endl;
cout<<"status of study : "<<response2<<endl;
cout<<"number of credits : "<<endl;
cout<<fee<<endl;
if (n >= 9)
{
fee = (400 * n * 0.35) + (43 * 9) + 10;
cout<<"status of residence : " << response1<<endl;
cout<<"status of study : "<<response2<<endl;
cout<<"number of credits : "<<endl;
cout<<fee<<endl;
}
}
}
inFile.close();
return 0;
}
this is my txt file,
i u n
i g n
o u n
o g n
i don't know if it's right . Please help me
i'm writing a program which calculates registration fee of student and this program opens an external txt file.It's my first time writing a program with an input file so i'm kinda confused.my program asks for the status and number of credits but does not gimme the fee.
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdlib>
#include<conio.h>
#include<cmath>
using namespace std;
int main()
{
string filename = "registration fee.txt";
ifstream inFile;
int n;
double fee;
char response1,response2;
char i,o,u,g;
inFile.open("registration fee.txt");
cout<<"please enter your status of residence,type i or o"<<endl;
cin>>response1;
cout<<"please enter your status of study,type u or g"<<endl;
cin>>response2;
cout<<"please enter your number of credits"<<endl;
cin>>n;
i = 0;
u = 0;
if ((response1 == i)&& (response2 == u))
{
if (n < 12)
{
fee = ((280 *n *0.35)+ (43 * n));
cout<<"status of residence : " << response1<<endl;
cout<<"status of study : "<<response2<<endl;
cout<<"number of credits : "<<endl;
cout<<fee<<endl;
if (n >= 12)
{
fee = ((280 *n *0.35)+ (43 * 12));
cout<<"status of residence : " << response1<<endl;
cout<<"status of study : "<<response2<<endl;
cout<<"number of credits : "<<endl;
}
}
}
g = 0;
if((response1 == i) && (response2 == g))
{
if (n < 9)
{
fee = (400 * n * 0.35) + (43 * n) + 10;
cout<<"status of residence : " << response1<<endl;
cout<<"status of study : "<<response2<<endl;
cout<<"number of credits : "<<endl;
cout<<fee<<endl;
if (n >= 9)
{
fee = (400 * n * 0.35) + (43 * 9) + 10;
cout<<"status of residence : " << response1<<endl;
cout<<"status of study : "<<response2<<endl;
cout<<"number of credits : "<<endl;
cout<<fee<<endl;
}
}
}
o = 1;
if ((response1 == o)&& (response2 == u))
{
if (n < 12)
{
fee = (280 * n) + (43 * n);
cout<<"status of residence : " << response1<<endl;
cout<<"status of study : "<<response2<<endl;
cout<<"number of credits : "<<endl;
cout<<fee<<endl;
if (n >= 12)
{
fee = (280 * n) + (43 * 12);
cout<<"status of residence : " << response1<<endl;
cout<<"status of study : "<<response2<<endl;
cout<<"number of credits : "<<endl;
cout<<fee<<endl;
}
}
}
if ((response1 == o) && (response2 == g))
{
if (n < 9)
{
fee = (400 * n * 0.35) + (43 * n) + 10;
cout<<"status of residence : " << response1<<endl;
cout<<"status of study : "<<response2<<endl;
cout<<"number of credits : "<<endl;
cout<<fee<<endl;
if (n >= 9)
{
fee = (400 * n * 0.35) + (43 * 9) + 10;
cout<<"status of residence : " << response1<<endl;
cout<<"status of study : "<<response2<<endl;
cout<<"number of credits : "<<endl;
cout<<fee<<endl;
}
}
}
inFile.close();
return 0;
}
this is my txt file,
i u n
i g n
o u n
o g n
i don't know if it's right . Please help me
A few things that stand out are:
-You're reading a file but what are you actually doing with it?
Those letters should be surrounded with apostrophes like so
-Are those nested if statements actually what you want? I don't think so.
I don't know, have a look at the code below....
-You're reading a file but what are you actually doing with it?
if ((response1 == o)&& (response2 == u))Those letters should be surrounded with apostrophes like so
'o' 'u'-Are those nested if statements actually what you want? I don't think so.
I don't know, have a look at the code below....
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
using namespace std;
int main()
{
string filename = "registration fee.txt";
ifstream inFile;
int n;
double fee;
char response1, response2;
char i, o, u, g;
inFile.open ( "registration fee.txt" );
cout << "please enter your status of residence,type i or o" << endl;
cin >> response1;
cout << "please enter your status of study,type u or g" << endl;
cin >> response2;
cout << "please enter your number of credits" << endl;
cin >> n;
i = 0;
u = 0;
if ( ( response1 == 'i' ) && ( response2 == 'u' ) )
{
if ( n < 12 )
{
fee = ( ( 280 * n * 0.35 ) + ( 43 * n ) );
cout << "status of residence : " << response1 << endl;
cout << "status of study : " << response2 << endl;
cout << "number of credits : " << endl;
cout << fee << endl;
}
else if ( n >= 12 )
{
fee = ( ( 280 * n * 0.35 ) + ( 43 * 12 ) );
cout << "status of residence : " << response1 << endl;
cout << "status of study : " << response2 << endl;
cout << "number of credits : " << endl;
cout << fee << endl;
}
}
g = 0;
if ( ( response1 == 'i' ) && ( response2 == 'g' ) )
{
if ( n < 9 )
{
fee = ( 400 * n * 0.35 ) + ( 43 * n ) + 10;
cout << "status of residence : " << response1 << endl;
cout << "status of study : " << response2 << endl;
cout << "number of credits : " << endl;
cout << fee << endl;
}
else if ( n >= 9 )
{ fee = ( 400 * n * 0.35 ) + ( 43 * 9 ) + 10;
cout << "status of residence : " << response1 << endl;
cout << "status of study : " << response2 << endl;
cout << "number of credits : " << endl;
cout << fee << endl;
}
}
o = 1;
if ( ( response1 == 'o' ) && ( response2 == 'u' ) )
{
if ( n < 12 )
{
fee = ( 280 * n ) + ( 43 * n );
cout << "status of residence : " << response1 << endl;
cout << "status of study : " << response2 << endl;
cout << "number of credits : " << endl;
cout << fee << endl;
}
else if ( n >= 12 )
{
fee = ( 280 * n ) + ( 43 * 12 );
cout << "status of residence : " << response1 << endl;
cout << "status of study : " << response2 << endl;
cout << "number of credits : " << endl;
cout << fee << endl;
}
}
if ( ( response1 == 'o' ) && ( response2 == 'g' ) )
{
if ( n < 9 )
{
fee = ( 400 * n * 0.35 ) + ( 43 * n ) + 10;
cout << "status of residence : " << response1 << endl;
cout << "status of study : " << response2 << endl;
cout << "number of credits : " << endl;
cout << fee << endl;
}
else if ( n >= 9 )
{ fee = ( 400 * n * 0.35 ) + ( 43 * 9 ) + 10;
cout << "status of residence : " << response1 << endl;
cout << "status of study : " << response2 << endl;
cout << "number of credits : " << endl;
cout << fee << endl;
}
}
inFile.close();
system ( "pause" );
return 0;
} Last edited by iamthwee; Oct 13th, 2007 at 2:56 pm.
*Voted best profile in the world*
![]() |
Similar Threads
- C Programming-Adding overdraft fee (C)
- What exactly is Fedora? (Getting Started and Choosing a Distro)
- parking fee (C++)
- new windosw xp full install edition; won't replace existing Windows Me OS (Windows NT / 2000 / XP)
- Has Acacia threatened to sue you yet? (Geeks' Lounge)
- Where can I buy a good computer? (Geeks' Lounge)
- embPerl or PHP (Perl)
Other Threads in the C++ Forum
- Previous Thread: 2 errors
- Next Thread: Flipping coin
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count data delete deploy desktop developer directshow dll download dynamic encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node number output parameter pointer problem program programming project proxy python read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






Can you explain what the file is for though? Or are you going to work on that now? 